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.*;
import java.lang.*;
import java.io.*;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.sqrt;
import static java.lang.Math.abs;
import static java.lang.Math.random;
import static java.lang.Integer.MAX_VALUE;
import static java.lang.Integer.MIN_VALUE;
import static java.util.Collections.reverseOrder;

public final class Test {
	static int mod = 1000000007;
	static int mod1 = 998244353;
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		solve();
	}
	static long gcd(int a, int b)              {if (b == 0) return a;	return gcd(b, a % b); }
	static long modAdd(long a, long b, long m) {a = a % m; b = b % m; return (((a + b) % m) + m) % m;}
	static long modMul(long a, long b, long m) {a = a % m; b = b % m; return (((a * b) % m) + m) % m;}
	static long modSub(long a, long b, long m) {a = a % m; b = b % m; return (((a - b) % m) + m) % m;}
	static long modDiv(long a, long b, long m) {a = a % m; b = b % m; return (modMul(a, mminvprime(b, m), m) + m) % m;}  //only for prime m
	static long mminvprime(long a, long b)     {return expo(a, b - 2, b);}
	static long expo(long a, long b, long mod) {long res = 1; while (b > 0) {if ((b & 1) != 0)res = (res * a) % mod; a = (a * a) % mod; b = b >> 1;} return res;}
	static long setBits(int n)                 {int cnt = 0;  while (n != 0)   { cnt++; n = n & (n - 1);  }   return cnt;}
	static int[] sieve(int n)                  {int[] arr = new int[n + 1];  for (int i = 2; i <= n; i++)if (arr[i] == 0) {for (int j = 2 * i; j <= n; j += i)arr[j] = 1;} return arr;}
	static void debug(int[] nums)              { for (int i = 0; i < nums.length; i++)	System.out.println(nums[i] + " "); }
	static void debug(long[] nums)             { for (int i = 0; i < nums.length; i++)	System.out.println(nums[i] + " "); }
	static void debug(String[] nums)           { for (int i = 0; i < nums.length; i++)	System.out.println(nums[i] + " "); }
	static void reverse(int[] nums)            { int start = 0, end = nums.length - 1;      while (start < end) {int temp = nums[start]; nums[start] = nums[end]; nums[end] = temp; start++; end--; }  }
	static void reverse(char[] nums)            { int start = 0, end = nums.length - 1;      while (start < end) {char temp = nums[start]; nums[start] = nums[end]; nums[end] = temp; start++; end--; }  }


	static class Pair implements Comparable<Pair> {
		int row, col;
		Pair(int row, int col) {
			this.row = row;
			this.col = col;
		}
		public int compareTo(Pair p) {
			// // for ascending   return p - this;    // for decending  return this-p;
			// ascending means-----MAX HEAP   //   Descending means-----MIN HEAP
			return 0;
		}
	}






//	<------------------------- code start from here -------------------------------->
	static void solve() {

		int waste = sc.nextInt();
		String str = sc.next();
		int  n = str.length();
		char ch[] = str.toCharArray();
		reverse(ch);

		long dp[]  = new long[n];
		for (int i = n - 1; i >= 0; i--)
			fill(dp, ch, i);
		// debug(dp);
		int q = sc.nextInt();
		while (q != 0) {
			--q;
			int p = sc.nextInt();
			char c = sc.next().charAt(0);
			ch[n - p] = c;
			update(n - p, dp, ch);
			System.out.println(dp[0]);
		}



	}
	static void fill(long[] dp, char[] ch, int index) {


		int left = 2 * index + 1;
		int right = 2 * index + 2;
		int n  = dp.length;
		if (left >= n) {
			if (ch[index] == '?')
				dp[index] = 2;
			else
				dp[index] = 1;
			return;
		}

		if (ch[index] == '?')
			dp[index] = dp[left] +  dp[right];
		else if (ch[index] == '0')
			dp[index] = dp[right];
		else
			dp[index] = dp[left];
	}

	static void update(int index, long[] dp, char[] ch) {
		while (index > 0) {
			fill(dp, ch, index);
			index = ( (index - 1) / 2);
		}
		fill(dp, ch, 0);
	}















}


// System.out.println();