```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; i++) {
    prefixSum[i] = [0];
    for (let j = 0; j < width; j++) {
      if (j > 0) {
        prefixSum[i][j] = prefixSum[i][j - 1];
      }
      prefixSum[i][j] += grid[i][j];
      // Handle negative numbers by setting to zero
      if (prefixSum[i][j] < 0) {
        prefixSum[i][j] = 0;
      }
    }
  }

  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");
    }
    const [t, l, b, r] = [Math.max(top, 0), Math.max(left, 0), bottom, right];
    if (t >= b || l >= r) {
      throw new Error("query boundaries must be valid");
    }

    result.push(
      prefixSum[b][r] - (l > 0 ? prefixSum[b][l - 1] : 0) -
        (t > 0 ? prefixSum[t - 1][r] : 0) +
        (l > 0 && t > 0 ? prefixSum[t - 1][l - 1] : 0)
    );
  }

  return result;
}
```