Problem: 2^k teams participate in a playoff tournament. The tournament consists of 2^k - 1 games. They are held as follows: first of all, the teams are split into pairs: team 1 plays against team 2, team 3 plays against team 4 (exactly in this order), and so on (so, 2^{k-1} games are played in that phase). When a team loses a game, it is eliminated, and each game results in elimination of one team (there are no ties). After that, only 2^{k-1} teams remain. If only one team remains, it is declared the champion; otherwise, 2^{k-2} games are played: in the first one of them, the winner of the game "1 vs 2" plays against the winner of the game "3 vs 4", then the winner of the game "5 vs 6" plays against the winner of the game "7 vs 8", and so on. This process repeats until only one team remains.

For example, this picture describes the chronological order of games with k = 3:

<image>

Let the string s consisting of 2^k - 1 characters describe the results of the games in chronological order as follows:

  * if s_i is 0, then the team with lower index wins the i-th game; 
  * if s_i is 1, then the team with greater index wins the i-th game; 
  * if s_i is ?, then the result of the i-th game is unknown (any team could win this game). 



Let f(s) be the number of possible winners of the tournament described by the string s. A team i is a possible winner of the tournament if it is possible to replace every ? with either 1 or 0 in such a way that team i is the champion.

You are given the initial state of the string s. You have to process q queries of the following form: 

  * p c — replace s_p with character c, and print f(s) as the result of the query. 

Input

The first line contains one integer k (1 ≤ k ≤ 18).

The second line contains a string consisting of 2^k - 1 characters — the initial state of the string s. Each character is either ?, 0, or 1.

The third line contains one integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of queries.

Then q lines follow, the i-th line contains an integer p and a character c (1 ≤ p ≤ 2^k - 1; c is either ?, 0, or 1), describing the i-th query.

Output

For each query, print one integer — f(s).

Example

Input


3
0110?11
6
5 1
6 ?
7 ?
1 ?
5 ?
1 1


Output


1
2
3
3
5
4

Solution (in JAVA):

Solution:
//package D;

import java.io.*;
import java.math.BigInteger;
import java.util.InputMismatchException;

public class Main {
  private static final InputReader in = new InputReader();
  private static final PrintWriter out = new PrintWriter(System.out);

  static int k;
  static char[] s;
  public static void main(String[] args) {
    k = in.readInt();
    s = in.readCharArray((int) Math.pow(2, k) - 1);

    SegmentTree t = new SegmentTree(s, k);
    int q = in.readInt();
    while (q-- > 0) {
      int pos = in.readInt();
      --pos;
      char op = in.readCharacter();
      t.update(t.posToNode[pos], op);

      out.println(t.tree[1].sum);
    }
    out.flush();
  }
}

class Node {
  int sum;
  char op;

  public Node() {
  }

  public Node(int sum, char op) {
    this.sum = sum;
    this.op = op;
  }
}

class SegmentTree {
  Node[] tree;
  int[] posToNode; // given pos in string, returns node index in tree
  int N;
  int K;

  public SegmentTree(char[] arr, int k) {
    tree = new Node[arr.length+1];
    posToNode = new int[arr.length+1];
    for (int i = 0; i < tree.length; ++i) {
      tree[i] = new Node();
    }
    N = (int) Math.pow(2, k - 1);
    K = k;

    int pos = 0;
    for (int i = 1; i <= k; ++i) {
      for (int j = (int) Math.pow(2, k - i); j < (int) Math.pow(2, k - i + 1); ++j) {
        tree[j].op = arr[pos];
        posToNode[pos++] = j;
      }
      System.err.println();
    }

    build(1, 0, N - 1);
  }

  void build(int node, int start, int end) {
    if (start == end) {
      if (tree[node].op == '1' || tree[node].op == '0') {
        tree[node].sum = 1;
      } else {
        tree[node].sum = 2;
      }
    } else {
      int mid = (start + end) >> 1;
      build(node*2, start, mid);
      build(node*2+1, mid+1, end);

      if (tree[node].op == '1') {
        tree[node].sum = tree[node*2+1].sum;
      } else if (tree[node].op == '0') {
        tree[node].sum = tree[node*2].sum;
      } else {
        tree[node].sum = tree[node*2].sum + tree[node*2+1].sum;
      }
    }
  }

  void update(int node, char op) {
    tree[node].op = op;
    if (isLeafNode(node)) {
      if (tree[node].op == '1' || tree[node].op == '0') {
        tree[node].sum = 1;
      } else {
        tree[node].sum = 2;
      }
    } else {
      if (tree[node].op == '1') {
        tree[node].sum = tree[node*2+1].sum;
      } else if (tree[node].op == '0') {
        tree[node].sum = tree[node*2].sum;
      } else {
        tree[node].sum = tree[node*2].sum + tree[node*2+1].sum;
      }
    }

    node >>= 1;
    while (node > 0) {
      if (tree[node].op == '1') {
        tree[node].sum = tree[node*2+1].sum;
      } else if (tree[node].op == '0') {
        tree[node].sum = tree[node*2].sum;
      } else {
        tree[node].sum = tree[node*2].sum + tree[node*2+1].sum;
      }
      node >>= 1;
    }
  }

  private boolean isLeafNode(int node) {
    return node >= (int) Math.pow(2, K - 1);
  }
}

/**
 * @author Egor Kulikov (kulikov@devexperts.com)
 */
class InputReader {
  private boolean finished = false;
  private static final int BUFFER_SIZE = 1 << 16;

  private InputStream stream;
  private byte[] buf = new byte[1024];
  private int curChar;
  private int numChars;

  public InputReader() {
    this.stream = new BufferedInputStream(System.in, BUFFER_SIZE);
  }

  public InputReader(String s) {
    try {
      this.stream = new BufferedInputStream(new FileInputStream(s), BUFFER_SIZE);
    } catch (Exception e) {
      this.stream = new BufferedInputStream(System.in, BUFFER_SIZE);
    }
  }

  public InputReader(InputStream stream) {
    this.stream = stream;
  }

  public double[] readDoubleArray(int size) {
    double[] array = new double[size];
    for (int i = 0; i < size; i++) {
      array[i] = readDouble();
    }
    return array;
  }

  public String[] readStringArray(int size) {
    String[] array = new String[size];
    for (int i = 0; i < size; i++) {
      array[i] = readString();
    }
    return array;
  }

  public char[] readCharArray(int size) {
    char[] array = new char[size];
    for (int i = 0; i < size; i++) {
      array[i] = readCharacter();
    }
    return array;
  }

  public String readText() {
    StringBuilder result = new StringBuilder();
    while (true) {
      int character = read();
      if (character == '\r') {
        continue;
      }
      if (character == -1) {
        break;
      }
      result.append((char) character);
    }
    return result.toString();
  }

  public long[] readLongArray(int size) {
    long[] array = new long[size];
    for (int i = 0; i < size; i++) {
      array[i] = readLong();
    }
    return array;
  }

  public int[] readIntArray(int size) {
    int[] array = new int[size];
    for (int i = 0; i < size; i++) {
      array[i] = readInt();
    }
    return array;
  }

  public int read() {
    if (numChars == -1) {
      throw new InputMismatchException();
    }
    if (curChar >= numChars) {
      curChar = 0;
      try {
        numChars = stream.read(buf);
      } catch (IOException e) {
        throw new InputMismatchException();
      }
      if (numChars <= 0) {
        return -1;
      }
    }
    return buf[curChar++];
  }

  public int peek() {
    if (numChars == -1) {
      return -1;
    }
    if (curChar >= numChars) {
      curChar = 0;
      try {
        numChars = stream.read(buf);
      } catch (IOException e) {
        return -1;
      }
      if (numChars <= 0) {
        return -1;
      }
    }
    return buf[curChar];
  }

  public int peekNonWhitespace() {
    while (isWhitespace(peek())) {
      read();
    }
    return peek();
  }

  public int readInt() {
    int c = read();
    while (isSpaceChar(c)) {
      c = read();
    }
    int sgn = 1;
    if (c == '-') {
      sgn = -1;
      c = read();
    }
    int res = 0;
    do {
      if (c < '0' || c > '9') {
        throw new InputMismatchException();
      }
      res *= 10;
      res += c - '0';
      c = read();
    } while (!isSpaceChar(c));
    return res * sgn;
  }

  public long readLong() {
    int c = read();
    while (isSpaceChar(c)) {
      c = read();
    }
    int sgn = 1;
    if (c == '-') {
      sgn = -1;
      c = read();
    }
    long res = 0;
    do {
      if (c < '0' || c > '9') {
        throw new InputMismatchException();
      }
      res *= 10;
      res += c - '0';
      c = read();
    } while (!isSpaceChar(c));
    return res * sgn;
  }

  public String readString() {
    int c = read();
    while (isSpaceChar(c)) {
      c = read();
    }
    StringBuilder res = new StringBuilder();
    do {
      if (Character.isValidCodePoint(c)) {
        res.appendCodePoint(c);
      }
      c = read();
    } while (!isSpaceChar(c));
    return res.toString();
  }

  public boolean isSpaceChar(int c) {
    return isWhitespace(c);
  }

  public static boolean isWhitespace(int c) {
    return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  }

  private String readLine0() {
    StringBuilder buf = new StringBuilder();
    int c = read();
    while (c != '\n' && c != -1) {
      if (c != '\r') {
        buf.appendCodePoint(c);
      }
      c = read();
    }
    return buf.toString();
  }

  public String readLine() {
    String s = readLine0();
    while (s.trim().length() == 0) {
      s = readLine0();
    }
    return s;
  }

  public String readLine(boolean ignoreEmptyLines) {
    if (ignoreEmptyLines) {
      return readLine();
    } else {
      return readLine0();
    }
  }

  public BigInteger readBigInteger() {
    try {
      return new BigInteger(readString());
    } catch (NumberFormatException e) {
      throw new InputMismatchException();
    }
  }

  public char readCharacter() {
    int c = read();
    while (isSpaceChar(c)) {
      c = read();
    }
    return (char) c;
  }

  public double readDouble() {
    int c = read();
    while (isSpaceChar(c)) {
      c = read();
    }
    int sgn = 1;
    if (c == '-') {
      sgn = -1;
      c = read();
    }
    double res = 0;
    while (!isSpaceChar(c) && c != '.') {
      if (c == 'e' || c == 'E') {
        return res * Math.pow(10, readInt());
      }
      if (c < '0' || c > '9') {
        throw new InputMismatchException();
      }
      res *= 10;
      res += c - '0';
      c = read();
    }
    if (c == '.') {
      c = read();
      double m = 1;
      while (!isSpaceChar(c)) {
        if (c == 'e' || c == 'E') {
          return res * Math.pow(10, readInt());
        }
        if (c < '0' || c > '9') {
          throw new InputMismatchException();
        }
        m /= 10;
        res += (c - '0') * m;
        c = read();
      }
    }
    return res * sgn;
  }

  public boolean isExhausted() {
    int value;
    while (isSpaceChar(value = peek()) && value != -1) {
      read();
    }
    return value == -1;
  }

  public String next() {
    return readString();
  }
}