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:
//Utilities
import java.io.*;
import java.util.*;

public class Main {
	static int k, n;
	static int[] dp;
	static char[] ch;
	static int[] mapL, mapR, next;
	static int lim;
	static int q;
	static int p;
	static char cc;
	
	public static void main(String[] args) throws IOException {
		k = in.iscan();
		ch = in.sscan().toCharArray(); n = ch.length;
		mapL = new int[n]; mapR = new int[n]; next = new int[n];
		int cur = (int)Math.pow(2, k) - 1, start = 0, cnt = 0, par = 0;
		for (int i = 0; i < n-1; i++) {
			int jump = Integer.highestOneBit(cur);
			if ((start | jump) > start) {
				start |= jump;
				cnt = 0;
			}
			start |= jump;
			if (par == 0) {
				mapL[start + cnt / 2] = i;
				next[i] = start + cnt / 2;
			}
			else {
				mapR[start + cnt / 2] = i;
				next[i] = start + cnt / 2;
			}
			cur--; par ^= 1; cnt++;
		}
//		for (int i = 0; i < n; i++) {
//			out.println(mapL[i] + " " + mapR[i] + " " + next[i]);
//		}
		dp = new int[n];
		lim = Integer.highestOneBit(n);
		for (int i = 0; i < lim; i++) {
			if (ch[i] != '?') {
				dp[i] = 1;
			}
			else {
				dp[i] = 2;
			}
		}
		propogateBackwards(n-1);
		q = in.iscan();
		while (q-- > 0) {
			p = in.iscan() - 1; cc = in.sscan().charAt(0);
			if (cc != ch[p]) {
				if (cc == '0') {
					if (p < lim) {
						dp[p] = 1;
					}
					else {
						dp[p] = dp[mapL[p]];
					}
				}
				else if (cc == '1') {
					if (p < lim) {
						dp[p] = 1;
					}
					else {
						dp[p] = dp[mapR[p]];
					}
				}
				else if (cc == '?'){
					if (p < lim) {
						dp[p] = 2;
					}
					else {
						dp[p] = dp[mapL[p]] + dp[mapR[p]];
					}
				}
				propogateForwards(next[p]);
			}
			out.println(dp[n-1]);
//			for (int i = 0; i < n; i++) {
//				out.print(dp[i] + " ");
//			}
//			out.println();
			ch[p] = cc;
		}
		out.close();
	}
	
	static void propogateForwards(int i) {
		if (i == 0) {
			return;
		}
		if (ch[i] == '0') {
			dp[i] = dp[mapL[i]];
		}
		else if (ch[i] == '1') {
			dp[i] = dp[mapR[i]];
		}
		else {
			dp[i] = dp[mapL[i]] + dp[mapR[i]];
		}
		propogateForwards(next[i]);
	}
	
	static void propogateBackwards(int i) {
		if (i < lim) {
			//out.println(i + " " + dp[i]);
			return;
		}
		propogateBackwards(mapL[i]); propogateBackwards(mapR[i]);
		if (ch[i] == '?') {
			dp[i] = dp[mapL[i]] + dp[mapR[i]];
		}
		else if (ch[i] == '0') {
			dp[i] = dp[mapL[i]];
		}
		else {
			dp[i] = dp[mapR[i]];
		}
		//out.println(i + " " + dp[i]);
	}
	
	static INPUT in = new INPUT(System.in);
	static PrintWriter out = new PrintWriter(System.out);
	private static class INPUT {

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

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

		public INPUT (String file) throws IOException {
			this.stream = new FileInputStream (file);
		}

		public int cscan () throws IOException {
			if (curChar >= numChars) {
				curChar = 0;
				numChars = stream.read (buf);
			}
			
			if (numChars == -1)
				return numChars;

			return buf[curChar++];
		}

		public int iscan () throws IOException {
			int c = cscan (), sgn = 1;
			
			while (space (c))
				c = cscan ();

			if (c == '-') {
				sgn = -1;
				c = cscan ();
			}

			int res = 0;

			do {
				res = (res << 1) + (res << 3);
				res += c - '0';
				c = cscan ();
			}
			while (!space (c));

			return res * sgn;
		}

		public String sscan () throws IOException {
			int c = cscan ();
			
			while (space (c))
				c = cscan ();

			StringBuilder res = new StringBuilder ();

			do {
				res.appendCodePoint (c);
				c = cscan ();
			}
			while (!space (c));

			return res.toString ();
		}

		public double dscan () throws IOException {
			int c = cscan (), sgn = 1;
			
			while (space (c))
				c = cscan ();

			if (c == '-') {
				sgn = -1;
				c = cscan ();
			}

			double res = 0;

			while (!space (c) && c != '.') {
				if (c == 'e' || c == 'E')
					return res * UTILITIES.fast_pow (10, iscan ());
				
				res *= 10;
				res += c - '0';
				c = cscan ();
			}

			if (c == '.') {
				c = cscan ();
				double m = 1;

				while (!space (c)) {
					if (c == 'e' || c == 'E')
						return res * UTILITIES.fast_pow (10, iscan ());

					m /= 10;
					res += (c - '0') * m;
					c = cscan ();
				}
			}

			return res * sgn;
		}

		public long lscan () throws IOException {
			int c = cscan (), sgn = 1;
			
			while (space (c))
				c = cscan ();

			if (c == '-') {
				sgn = -1;
				c = cscan ();
			}

			long res = 0;

			do {
				res = (res << 1) + (res << 3);
				res += c - '0';
				c = cscan ();
			}
			while (!space (c));

			return res * sgn;
		}

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

	public static class UTILITIES {

		static final double EPS = 10e-6;

		public static int lower_bound (int[] arr, int x) {
			int low = 0, high = arr.length, mid = -1;

			while (low < high) {
				mid = (low + high) / 2;

				if (arr[mid] >= x)
					high = mid;
				else
					low = mid + 1;
			}

			return low;
		}

		public static int upper_bound (int[] arr, int x) {
			int low = 0, high = arr.length, mid = -1;

			while (low < high) {
				mid = (low + high) / 2;

				if (arr[mid] > x)
					high = mid;
				else
					low = mid + 1;
			}

			return low;
		}

		public static long gcd (long a, long b) {
			return b == 0 ? a : gcd (b, a % b);
		}

		public static long lcm (long a, long b) {
			return a * b / gcd (a, b);
		}

		public static long fast_pow_mod (long b, long x, int mod) {
			if (x == 0) return 1;
			if (x == 1) return b;
			if (x % 2 == 0) return fast_pow_mod (b * b % mod, x / 2, mod) % mod;

			return b * fast_pow_mod (b * b % mod, x / 2, mod) % mod;
		}

		public static int fast_pow (int b, int x) {
			if (x == 0) return 1;
			if (x == 1) return b;
			if (x % 2 == 0) return fast_pow (b * b, x / 2);

			return b * fast_pow (b * b, x / 2);
		}

		public static long choose (long n, long k) {
			k = Math.min (k, n - k);
			long val = 1;

			for (int i = 0; i < k; ++i)
				val = val * (n - i) / (i + 1);

			return val;
		}

		public static long permute (int n, int k) {
			if (n < k) return 0;
			long val = 1;

			for (int i = 0; i < k; ++i)
				val = (val * (n - i));

			return val;
		}
	}
}