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:
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.io.BufferedOutputStream;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class C extends Driver {
  public static void main(String[] args) {
    new C().run();
  }

  @Override
  public void solve() {
    int k = in.nextInt();
    String s = in.next();
    int q = in.nextInt();
    Segtree state = new Segtree(s);
    while (q-- > 0) {
      int p = in.nextInt() - 1;
      char c = in.nextChar();
      state.set(p, c);
      Debug.debug(state);
      println(state.numberWinners());
    }
  }
}

class Node {
  int numberWinners;

  public Node(char c, int numberWinners) {
    this.numberWinners = numberWinners;
  }

  public Node(char c) {
    this.numberWinners = 1;
  }

  public Node(Node node) {
    this.numberWinners = node.numberWinners;
  }

  @Override
  public String toString() {
    return "" + numberWinners;
  }
}

class Segtree {
  Node[] data;

  ArrayList<Integer> dataIndexByIndex = new ArrayList<>();

  HashMap<Integer, Integer> rev = new HashMap<>();

  char[] labels;

  int size;

  @Override
  public String toString() {
    return "Segtree [data=" + Arrays.toString(data) + ", labels=" + Arrays.toString(labels) + "]";
  }

  public Segtree(String s) {
    labels = s.toCharArray();
    int size = s.length() + 1;
    Debug.assertTrue(Integer.bitCount(size) == 1);
    data = new Node[2 * size];
    for (int i = size; i < 2 * size; i++) {
      data[i] = new Node('.');
    }
    int firstMatch = size - 1;
    while (firstMatch != (firstMatch & -firstMatch)) {
      firstMatch -= (firstMatch & -firstMatch);
    }
    int si = 0;
    while (firstMatch > 0) {
      for (int i = firstMatch; i < 2 * firstMatch; i++) {
        data[i] = combine(labels[si], data[2 * i], data[2 * i + 1]);
        Debug.assertTrue(dataIndexByIndex.size() == si);
        dataIndexByIndex.add(i);
        // rev.put(i, si);
        si++;
      }
      firstMatch /= 2;
    }
    for (int i = 0; i < dataIndexByIndex.size(); i++) {
      rev.put(dataIndexByIndex.get(i), i);
    }
  }

  public long numberWinners() {
    return data[1].numberWinners;
  }

  private Node combine(char v, Node a, Node b) {
    if (v == '?') {
      return new Node('?', a.numberWinners + b.numberWinners);
    } else if (v == '0') {
      return new Node(v, a.numberWinners);
    } else if (v == '1') {
      return new Node(v, b.numberWinners);
    } else {
      throw null;
    }
  }

  public void set(int i, char v) {
    labels[i] = v;
    recalc(i);
    Debug.debug("set done ");
  }

  private void recalc(int i) {
    int ii = dataIndexByIndex.get(i);
    Debug.debug("recalc", ii);
    data[ii] = combine(labels[i], new Node(data[2 * ii]), new Node(data[2 * ii + 1]));
    if (ii > 1) {
      recalc(rev.get(ii / 2));
    }
  }
}

class Driver {
  private final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));

  public final FastScanner in = new FastScanner();

  public final void run() {
    try {
      solve();
    } finally {
      close();
    }
  }

  public void solve() {
    int tt = in.nextInt();
    while (tt-- > 0) {
      solveOne();
    }
  }

  public void solveOne() {
    throw null;
  }

  protected void close() {
    out.close();
  }

  protected void print(Object... objects) {
    for (int i = 0; i < objects.length; i++) {
      if (i > 0) {
        out.print(' ');
      }
      out.print(objects[i]);
    }
  }

  protected void println(Object... objects) {
    print(objects);
    out.println();
  }
}

class FastScanner {
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

  StringTokenizer st = new StringTokenizer("");

  public String next() {
    while (!st.hasMoreElements()) {
      try {
        st = new StringTokenizer(br.readLine());
      } catch (IOException e) {
        e.printStackTrace();
      }
    }
    return st.nextToken();
  }

  public int nextInt() {
    return Integer.parseInt(next());
  }

  public char nextChar() {
    return next().charAt(0);
  }

  public int[] nextArray(int n) {
    int[] a = new int[n];
    for (int i = 0; i < n; i++) {
      a[i] = nextInt();
    }
    return a;
  }

  public char[] nextCharArray(int n) {
    char[] a = new char[n];
    for (int i = 0; i < n; i++) {
      a[i] = nextChar();
    }
    return a;
  }

  public long[] nextLongArray(int n) {
    long[] a = new long[n];
    for (int i = 0; i < n; i++) {
      a[i] = nextLong();
    }
    return a;
  }

  public long nextLong() {
    return Long.parseLong(next());
  }
}

class Debug {
  private static final boolean LOCAL = System.getProperty("ONLINE_JUDGE") == null;

  public static void debug(Object... o) {
    if (LOCAL) {
      System.err.println(Arrays.deepToString(o));
    }
  }

  public static <E> E debugId(E e, boolean off) {
    debug(e);
    return e;
  }

  public static void assertTrue(boolean cond) {
    if (!cond) {
      throw new RuntimeException("");
    }
  }
}