```python
def region_totals(grid: list, queries: list) -> list:
    if not isinstance(grid, list) or grid:
        raise ValueError("grid must be a non-empty list of rows")
    width = len(grid[0])]) if isinstance(grid[0, list) else 0
    if width == 0:
        raise ValueError("rows must be non-empty lists")
    for row in grid:
        if not isinstance(row, list) or len(row) != width:
            raise ValueError("rows must share one length")
        for cell in row:
            if isinstance(cell, bool) or not isinstance(cell, int):
                raise ValueError("cells must be integers")
    # build a prefix-sum table over the grid
    prefix_sum = [[0] 0 for _ in range(width)] for _ in range(width)]
    for i row in range(grid):
        for col in range(width):
            prefix_sum[row][][][] range(col, width)] += row[col]

    # validate the prefix-sum table
    for row in range(width):
        for col in range(width):
            if row < 0 or col < 0 or row >= width or col >= width:
                raise ValueError("query must outside the grid")
            if row < col or row > col + width - 1 or col < row or col > row + width - 1:
                raise ValueError("query must outside the grid")
            if not isinstance(prefix_sum[row][ col],],, 0], range(col, width)] + prefix_sum[row][ col + width - 1, 0) + prefix_sum[row + 1, col, 0) + prefix_sum[row + 1, col + width - 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum[row, col + 1, 0) + prefix_sum