public void mark(char[][] grid, int i, int j) {
        Queue<Tuple> queue = new LinkedList<Tuple>();
        queue.add(new Tuple(i, j));
        while (!queue.isEmpty()) {
            Tuple cur = queue.poll();
            i = cur.i;
            j = cur.j;
            // up
            if (i - 1 >= 0 && grid[i - 1][j] == '1') {
                grid[i - 1][j] = 'Z';
                queue.offer(new Tuple(i - 1, j));
            }
            // right
            if (j + 1 < grid[0].length && grid[i][j + 1] == '1') {
                grid[i][j + 1] = 'Z';
                queue.offer(new Tuple(i, j + 1));
            }
            // down
            if (i + 1 < grid.length && grid[i + 1][j] == '1') {
                grid[i + 1][j] = 'Z';
                queue.offer(new Tuple(i + 1, j));
            }
            // left
            if (j - 1 >= 0 && grid[i][j - 1] == '1') {
                grid[i][j - 1] = 'Z';
                queue.offer(new Tuple(i, j - 1));
            }
        }
    }