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.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.StringTokenizer;

public class CodeForces {

    public static void main(String[] args) throws IOException {
        reader input = new reader();
        PrintWriter output = new PrintWriter(System.out);
        //BufferedReader bf = new BufferedReader(new FileReader("input.txt"));
        //PrintWriter pw = new PrintWriter(new BufferedWriter(new FileWriter("output.txt")));
        //StringTokenizer stk = new StringTokenizer(bf.readLine());
        //int n=Integer.parseInt(stk.nextToken());
        int k=input.nextInt();
        String s=input.next();
        int n=(1<<k)-1;
        Node dp[]=new Node[n];
        for(int i=0;i<n;i++){
            if(s.charAt(n-1-i)=='?'){
                dp[i]=new Node(-1);
            }else if(s.charAt(n-1-i)=='0'){
                dp[i]=new Node(0);
            }else
                dp[i]=new Node(1);
        }
        Build(0,dp,n);
        int q=input.nextInt();
        for(int i=0;i<q;i++){
            int index=input.nextInt();
            char ch=input.next().charAt(0);
            int status;
            if(ch=='?')
                status=-1;
            else
                status=ch-'0';
            dp[n-index].status=status;
            Update(n-index,dp,n);
            output.println(dp[0].num);
        }
        output.close();
    }
    public static void Build(int x,Node dp[],int n){
        if (x * 2 + 1 < n) {
            Build(x * 2 + 1,dp,n);
            Build(x * 2 + 2,dp,n);
            if (dp[x].status == -1) {
                dp[x].num = dp[x * 2+1].num + dp[x * 2 + 2].num;
            } else if (dp[x].status == 0) {
                dp[x].num = dp[x * 2 + 2].num;
            } else {
                dp[x].num = dp[x * 2+1].num;
            }
        } else {
            if (dp[x].status == -1) {
                dp[x].num = 2;
            } else {
                dp[x].num = 1;
            }
        }
    }
    public static void Update(int x,Node dp[],int n){
        if (x * 2 + 2 < n) {
            if (dp[x].status == -1) {
                dp[x].num = dp[x * 2+1].num + dp[x * 2 + 2].num;
            } else if (dp[x].status == 0) {
                dp[x].num = dp[x * 2 + 2].num;
            } else {
                dp[x].num = dp[x * 2+1].num;
            }
        } else {
            if (dp[x].status == -1) {
                dp[x].num = 2;
            } else {
                dp[x].num = 1;
            }
        }
        if(x!=0){
            Update((x-1)/2,dp,n);
        }
    }

    public static int GCD(int a,int b){
        if(a==0)
            return b;
        else if(b==0)
            return a;
        else
            return GCD(b%a,a);
    }

    public static boolean isPrime(long num){
        if(num==1)
            return false;
        else if(num==2||num==3)
            return true;
        else if(num%2==0||num%3==0)
            return false;
        else{
            for(long i=5;i*i<=num;i+=6){
                if(num%i==0||num%(i+2)==0)
                    return false;
            }
        }
        return true;
    }

    public static ArrayList<Integer> SieveofEratothenis(){
        ArrayList<Integer>ans=new ArrayList<>();
        boolean visited[]=new boolean[1000000];
        for(int i=2;i<1000000;i++){
            if(!visited[i]){
                ans.add(i);
                for(long j=(long)i*i;j<1000000;j+=i){
                    visited[(int)j]=true;
                }
            }
        }
        return ans;
    }

    public static void mergesort(long arr[],int start,int end){//start and end must be indexes
        if(start<end) {
            int mid=(start+end)/2;
            mergesort(arr,start,mid);
            mergesort(arr, mid+1, end);
            merge(arr, start,mid,end);
        }
    }
    public static void merge(long arr[],int start,int mid,int end){
        int lsize=mid-start+1,rsize=end-mid;
        long l[]=new long[lsize],r[]=new long[rsize];
        for(int i=start;i<=mid;i++){
            l[i-start]=arr[i];
        }
        for(int i=mid+1;i<=end;i++){
            r[i-mid-1]=arr[i];
        }
        int i=0,j=0,k=start;
        while(i<lsize&&j<rsize){
            if(l[i]<=r[j]){
                arr[k++]=l[i++];
            }else{
                arr[k++]=r[j++];
            }
        }
        while(i<lsize)
            arr[k++]=l[i++];
        while(j<rsize)
            arr[k++]=r[j++];
    }
}
class Node{
    int num;
    int status;
    Node(int status){
        this.status=status;
    }
}
class Pair{
    int index,val;
    Pair(int index,int val){
        this.index=index;
        this.val=val;
    }
}
class reader {
    BufferedReader br;
    StringTokenizer st;

    public reader() {
        br = new BufferedReader(new
                InputStreamReader(System.in));
    }

    String next() {
        while (st == null || !st.hasMoreElements()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return st.nextToken();
    }

    int nextInt() {
        return Integer.parseInt(next());
    }

    long nextLong() {
        return Long.parseLong(next());
    }

    double nextDouble() {
        return Double.parseDouble(next());
    }

    String nextLine() {
        String str = "";
        try {
            str = br.readLine();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return str;
    }

    public int[] nextIntArray(int arraySize) {
        int array[] = new int[arraySize];
        for (int i = 0; i < arraySize; i++) {
            array[i] = nextInt();
        }
        return array;
    }

    public long[] nextLongArray(int arraySize) {
        long array[] = new long[arraySize];
        for (int i = 0; i < arraySize; i++) {
            array[i] = nextLong();
        }
        return array;
    }
}