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 CPP):

Solution:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include "bits/stdc++.h"
using namespace std;

#define fastio ios_base::sync_with_stdio(0);cin.tie(0)
#define pb push_back
#define mp make_pair
#define forstl(i,v) for(auto &i: v)
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x

#define testcase(t) int t;cin>>t;while(t--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> p64;
typedef pair<int, int> p32;
typedef pair<int, p32> p96;
typedef vector<ll> vll;
typedef vector<int> v32;
typedef vector<v32> vv32;
typedef vector<vll> vvll;
typedef vector<p32> vp32;
typedef vector<p64> vp64;
typedef vector<vp32> vvp32;
typedef map<int, int> m32;

const int LIM = 2e5 + 5, MOD = 1e9 + 7;
const ld EPS = 1e-9;

void bandev() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
bool isPrimeSeive(ll k) {
	if (k == 1) return false;
	if (k == 2) return true;
	if (k % 2 == 0) return false;
	bitset <1000> bs;
	for (int i = 2; i <= k; i++) {
		if (bs[i] == 0) {
			for (int j = i * i; j <= k; j += i) {
				bs |= 1 << j;
			}
		}
	}
	if (bs[k]) return false;
	return true;
}

ll nthPrime(ll n) {
	if (n == 0) return 1;
	ll k = 1;
	bitset <1000> bs(3);
	for (int i = 3; i <= 1000; i += 2) {
		if (bs[i] == 0) k++;
		if (k == n) {
			return i;
		}
		if (bs[i] == 0) {
			for (int j = i * i; j <= 1000; j += i) {
				bs[j] = 1;
			}
		}
	}
	return 2;
}

int gcd(ll a, ll b)
{
	if (b == 0)
		return a;
	return gcd(b, a % b);
}

int lcm(ll a, ll b)
{
	return a * b / gcd(a, b);
}

void printArr(vll nw) {
	for (ll i = 0; i < nw.size(); i++)
		cout << nw[i] << " ";
	cout << endl;
}
void printMat(vvll mat) {
	for (ll i = 0 ; i < mat.size() ; i++) {
		for (ll j = 0; j < mat[i].size() ; j++) {
			printf("%d ", int(mat[i][j]));
		}
		printf("\n");
	}
	return;
}
ll sizeDecimal(ll k) {
	if (k == 0) return 1;
	ll num = 0;
	while (k > 0) {
		num++;
		k /= 10;
	}
	return num;
}

ll sz(vll arr) {
	if (arr.empty()) return 0;
	return arr.size();
}

bool isPrime(ll k) {
	if (k == 1) return false;
	if (k == 2) return true;
	if (k % 2 == 0) return false;
	for (int i = 3; i * i <= k; i += 2) {
		if (k % i == 0) return false;
	}
	return true;
}

vector<ll> dp;

ll retPow(ll n) {
	if (dp[n] > -1) return dp[n];
	if (n % 2 == 0) dp[n] = (retPow(n / 2) * retPow(n / 2)) % MOD;
	else dp[n] = (((retPow(n / 2) * retPow(n / 2)) % MOD) * 2) % MOD;
	return dp[n];
}

ll retNow(ll n, ll m) {
	if (m == 0) return 1;
	if (m % 2 == 0) return (retNow(n, m / 2) * retNow(n, m / 2)) % MOD;
	return (((retNow(n, m / 2) * retNow(n, m / 2)) % MOD) * n) % MOD;
}

ll ret(ll j) {
	if (j == 1) return 0;
	return 1 + ret(j / 2);
}

void run_case(ll t) {
	ll n;
	cin >> n;
	string str;
	cin >> str;
	ll tot = ll(pow(2, n) - 1);
	vector<string> mat;
	vvll mt;
	ll st = 0, len = ll(pow(2, n - 1));
	while (len >= 1) {
		string vec(str.begin() + st, str.begin() + st + len);
		mat.pb(vec);
		st += len;
		len /= 2;
	}
	for (ll i = 0; i < mat.size(); i++) {
		//cout << mat[i] << endl;
		vll mw;
		if (i == 0) {
			for (ll j = 0; j < mat[i].size(); j++) {
				if (mat[i][j] != '?') mw.pb(1);
				if (mat[i][j] == '?') mw.pb(2);
			}
		}
		else {
			for (ll j = 0; j < mat[i].size(); j++) {
				if (mat[i][j] == '0') {
					mw.pb(mt[i - 1][2 * j]);
				}
				else if (mat[i][j] == '1') {
					mw.pb(mt[i - 1][2 * j + 1]);
				}
				else {
					mw.pb(mt[i - 1][2 * j + 1] + mt[i - 1][2 * j]);
				}
			}
		}
		mt.pb(mw);
	}
	ll q;
	cin >> q;
	for (ll i = 0; i < q; i++) {
		ll ind;
		cin >> ind;
		char c;
		cin >> c;
		ll idx = ret(tot - ind + 1);
		ll dst = ll(pow(2, idx)) - 1 - (tot - ind) + ll(pow(2, idx) - 1);
		//cout << " ind: " << ind  << " idx: " << idx << " dst: " << dst << endl;
		mat[n - 1 - idx][dst] = c;
		// for (ll i = 0; i < mat.size(); i++) {
		// 	cout << mat[i] << endl;
		// }
		for (ll j = n - 1 - idx; j < n; j++) {
			if (j == 0) {
				if (mat[j][dst] != '?') mt[j][dst] = 1;
				if (mat[j][dst] == '?') mt[j][dst] = 2;
			}
			else {
				if (mat[j][dst] == '0') {
					mt[j][dst] = mt[j - 1][2 * dst];
				}
				else if (mat[j][dst] == '1') {
					mt[j][dst] = mt[j - 1][2 * dst + 1];
				}
				else {
					mt[j][dst] = mt[j - 1][2 * dst + 1] + mt[j - 1][2 * dst];
				}
			}
			dst = dst / 2;
		}
		cout << mt[n - 1][0] << endl;
	}
}


int main()
{
	ll n = 1;
	//cin >> n;
	for (ll i = 0; i < n; i++) {
		run_case(i + 1);
	}
	return 0;
}