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.Scanner;

public class Main{
	
	public static void main(String[] args) {
		
		Scanner s=new Scanner(System.in);
		
		
			
			int k=s.nextInt();
			
			char[] brr=s.next().toCharArray();
			char[] a=new char[brr.length];
			for(int i=brr.length-1;i>=0;i--) {
				a[brr.length-1-i]=brr[i];
				
			}
			
			int n=brr.length+1;
			
			pair[] arr=new pair[brr.length+1];
			
			for(int i=0;i<n;i++) {
				arr[i]=new pair(0,0,0);
			}
			
			
			
			
			for(int i=n-1;i>=n/2;i--) {
				
				int x=0;
				if(a[i-1]=='0') {
					x=0;
				}else if(a[i-1]=='1') {
					x=1;
				}else {
					x=2;	
				}
				
				arr[i]=new pair(1,1,x);
				
			}
			
			
			for(int i=n/2-1;i>=1;i--) {
				
				int x=0;
				if(a[i-1]=='0') {
					x=0;
				}else if(a[i-1]=='1') {
					x=1;
				}else {
					x=2;	
				}
				
				pair node=new pair(0,0,0);
				
				if(arr[i*2+1].ans==0) {
					node.l=arr[i*2+1].l;
				}else if(arr[i*2+1].ans==1) {
					node.l=arr[i*2+1].r;
				}else {
					node.l=arr[i*2+1].l+arr[i*2+1].r;
					
				}
				if(arr[i*2].ans==0) {
					node.r=arr[i*2].l;
				}else if(arr[i*2].ans==1) {
					node.r=arr[i*2].r;
				}else {
					node.r=arr[i*2].l+arr[i*2].r;
					
				}
				
				node.ans=x;
				arr[i]=node;
				
				
				
			}
			
			StringBuilder sb=new StringBuilder();
		//System.out.println(00000000000000000000000000000000000000000000000000000000000000000);
			int q=s.nextInt();
			
			
			for(int ie=0;ie<q;ie++)
			{
				
				int x=s.nextInt();
				char y=s.next().charAt(0);
				x=n-x;
				
				int curr=x/2;
				int val=0;
				if(y=='0') {
					val=0;
				}else if(y=='1') {
					val=1;
				}else {
					val=2;
				}
				arr[x].ans=val;
				
				while(curr>0) {
					
					pair node=new pair(0,0,arr[curr].ans);
					
					if(arr[curr*2+1].ans==0) {
						node.l=arr[curr*2+1].l;
					}else if(arr[curr*2+1].ans==1) {
						node.l=arr[curr*2+1].r;
					}else {
						node.l=arr[curr*2+1].l+arr[curr*2+1].r;
						
					}
					if(arr[curr*2].ans==0) {
						node.r=arr[curr*2].l;
					}else if(arr[curr*2].ans==1) {
						node.r=arr[curr*2].r;
					}else {
						node.r=arr[curr*2].l+arr[curr*2].r;
						
					}
					arr[curr]=node;
					curr=curr/2;
					if(curr==0) {
						break;
					}
					
					
				}
				
				int g=arr[1].ans;
				if(g==0) {
					sb.append(arr[1].l+"\n");
				}else if(g==1) {
					sb.append(arr[1].r+"\n");
				}else {
					sb.append((arr[1].l+arr[1].r)+"\n");
				}
				

				
				
				
			}
			
		System.out.println(sb);	
		}
		
		
		
	}
	
class pair{
	int l;
	int r;
	int ans;
	public pair(int l,int r,int ans) {
		this.l=l;
		this.r=r;
		this.ans=ans;
	}
	
}