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

public class Sol{
static InputStream inputStream = System.in;
static OutputStream outputStream = System.out;
static FastReader in=new FastReader(inputStream);
static PrintWriter out=new PrintWriter(outputStream);

static class FastReader 
{ 
  BufferedReader br; 
  StringTokenizer st; 
 
  public FastReader(InputStream in) 
  { 
      br = new BufferedReader(new
               InputStreamReader(System.in)); 
  } 
 
  public String next() 
  { 
      while (st == null || !st.hasMoreElements()) 
      { 
          try
          { 
              st = new StringTokenizer(br.readLine()); 
          } 
          catch (IOException  e) 
          { 
              e.printStackTrace(); 
          } 
      } 
      return st.nextToken(); 
  } 
 
  public int nextInt() 
  { 
      return Integer.parseInt(next()); 
  } 
 
  public long nextLong() 
  { 
      return Long.parseLong(next()); 
  } 
 
 public  double nextDouble() 
  { 
      return Double.parseDouble(next()); 
  } 
 
 
  String nextLine() 
  { 
      String str = ""; 
      try
      { 
          str = br.readLine(); 
      } 
      catch (IOException e) 
      { 
          e.printStackTrace(); 
      } 
      return str; 
  } 
}
static int ni(){return in.nextInt();}
static long nl(){return in.nextLong();}
static String ns(){return in.nextLine();}

/*
//-----------------GRAPH--------------------------------------------------------------------------
static void DFS(int v,int p){
dp[0][v]=0;dp[1][v]=0;
for(int u:adj[v]){
if(u==p)continue;
DFS(u,v);
dp[0][v]+=Math.max(Math.abs(A[0][u]-A[0][v]) + dp[0][u], Math.abs(A[1][u]-A[0][v]) + dp[1][u] );
dp[1][v]+=Math.max(Math.abs(A[0][u]-A[1][v]) + dp[0][u], Math.abs(A[1][u]-A[1][v]) + dp[1][u] );
}

}

static int N=(int)Math.pow(10,5)+10;
static ArrayList<Integer> adj[]=new ArrayList[N];
static long dp[][]=new long[2][N];
static long A[][]=new long[2][N];

static class Edge implements Comparable<Edge>{
int destination;long cost;
Edge(int destination,long cost){this.cost=cost;this.destination=destination;}

@Override

		public int compareTo(Edge o) {
			return Long.compare(cost, o.cost);
		}
}
*/

//--------------------------M A T H  ----------------------------------------------------------
static long mod=1000000007;

static long fp(long x,long n){ 
               if (n == 0) {
        return 1;
    }
    else if (n % 2 == 0) {
        return fp((x * x) , n / 2);
    }
    else {
        return (x * fp((x * x) , (n - 1) / 2));
    }}
static long gcd(long a, long b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
  
static long modexp(long x, long n)
{
    if (n == 0) {
        return 1;
    }
    else if (n % 2 == 0) {
        return modexp((x * x) % mod, n / 2);
    }
    else {
        return (x * modexp((x * x) % mod, (n - 1) / 2) % mod);
    }
}
static long getFractionModulo(long a, long b)
{
    long c = gcd(a, b);a/=c;b/=c;
    long  d = modexp(b, mod - 2);
    return ((a % mod) * (d % mod)) % mod;
}
  
//-----------------------Combinatorial------------------------------------------------------

/*long Comb[][]=new long[61][61];
for(int i=1;i<=60;i++){Comb[i][0]=1;}
for(int i=1;i<=60;i++){Comb[i][1]=i;Comb[i][i]=1;}
for(int i=2;i<=60;i++){for(int j=1;j<i;j++){Comb[i][j]=Comb[i-1][j]+Comb[i-1][j-1];}}*/

//-----------------------Linear Sieve--------------------------------------------------------        

/*long d[]=new long[n];
for(int i=1;i<n;i++){ for(int j=i; j<n; j+=i){ d[j] += 1; }}
long pre[]=new long[n];
pre[1]=1;d[1]=1;
for(int i=2;i<n;i++){d[i]+=pre[i-1]%mod;pre[i] += (pre[i-1]+d[i])%mod;}*/




static class Pair implements Comparable<Pair>{
        int x;int y;int id;int next;
        public Pair(int x,int y,int next) {
          this.next=next;
          this.x=x;
         this.y=y;
        }
        @Override
        public int compareTo(Pair p){if(x==p.x){return y-p.y;} return x-p.x;}
       
      }

public static void main(String []args){

int t=1;

while(t-->0){
int k=ni();
String st=ns();int l=(int)Math.pow(2,k);
int total[]=new int[k+1];
for(int i=2;i<=k;i++){total[i]=(int)Math.pow(2,k-i+1);}
for(int i=2;i<=k;i++)total[i]+=total[i-1];
char s[]=new char[l];
for(int i=1;i<l;i++)s[i]=st.charAt(i-1);

int dp[][]=new int[k+1][l+1];
for(int i=1;i<=l;i++){dp[0][i]=1;}
for(int i=1;i<=k;i++){for(int j=1;j<=(int)Math.pow(2,k-i);j++){
        if(s[total[i]+j]=='1'){dp[i][j]=dp[i-1][2*j];}
        else if(s[total[i]+j]=='0'){dp[i][j]=dp[i-1][2*j-1];}
        else {dp[i][j]=dp[i-1][2*j-1]+dp[i-1][2*j];}
        
}}

Scanner sc=new Scanner(System.in);
int q=ni();
while(q-->0){

int x=ni();String s1=in.next();
int i=1;s[x]=s1.charAt(s1.length()-1);
while(i<=k&&x>total[i]){i++;}
i--;x-=total[i];
while(i<=k){
   
    if(s[total[i]+x]=='1'){dp[i][x]=dp[i-1][2*x];}
    else if(s[total[i]+x]=='0'){dp[i][x]=dp[i-1][2*x-1];}
    else{dp[i][x]=dp[i-1][2*x-1]+dp[i-1][2*x];}
    
    if(x%2!=0)x=x/2+1;
    else{x/=2;}
    i++;
}

out.println(dp[k][1]);
/*for(i=1;i<=k;i++){for(int j=1;j<=(int)Math.pow(2,k-i);j++){
       out.print(dp[i][j]+" ");
        
}out.println();}
*/
}




}out.close();}}