```typescript
export function regionTotals(grid: number[][], queries: number[][]): number[] {
  if (!Array.isArray(grid) || grid.length === 0) {
    throw new Error("grid must be a non-empty list of rows");
  }
  const width = Array.isArray(grid[0]) ? grid[0].length : 0;
  if (width === 0) {
    throw new Error("rows must be non-empty lists");
  }
  for (const row of grid) {
    if (!Array.isArray(row) || row.length !== width) {
      throw new Error("rows must all share one length");
    }
    for (const cell of row) {
      if (!Number.isInteger(cell)) {
        throw new Error("cells must be integers");
      }
    }
  }

  const prefixSum: number[][] = [];
  for (let i = 0; i < grid.length + 1; i++) {
    prefixSum.push(new Array(width + 1).fill(0));
  }

  for (let i = 1; i <= grid.length; i++) {
    for (let j = 1; j <= width; j++) {
      prefixSum[i][j] =
        prefixSum[i - 1][j] +
        prefixSum[i][j - 1] -
        prefixSum[i - 1][j - 1] +
        grid[i - 1][j - 1];
    }
  }

  const result: number[] = [];
  for (const [top, left, bottom, right] of queries) {
    if (
      !Array.isArray([top, left, bottom, right]) ||
      [top, left, bottom, right].length !== 4
    ) {
      throw new Error("queries must be lists of exactly four integers");
    }
    if (top >= bottom || left >= right) {
      throw new Error("query top must be strictly less than its bottom and query left must be strictly less than its right");
    }

    const topLeft = prefixSum[top][left];
    const topRight = prefixSum[top][right + 1];
    const bottomLeft = prefixSum[bottom + 1][left];
    const bottomRight = prefixSum[bottom + 1][right + 1];

    result.push(bottomRight - topRight - bottomLeft + topLeft);
  }

  return result;
}
```