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 D {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    
    public static void sort(int arr[],int l,int r) {    //sort(arr,0,n-1);
        if(l==r) {
            return;
        }
        int mid=(l+r)/2;
        sort(arr,l,mid);
        sort(arr,mid+1,r);
        merge(arr,l,mid,mid+1,r);
    }
    public static void merge(int arr[],int l1,int r1,int l2,int r2) {
        int tmp[]=new int[r2-l1+1];
        int indx1=l1,indx2=l2;
        //sorting the two halves using a tmp array
        for(int i=0;i<tmp.length;i++) {
            if(indx1>r1) {
                tmp[i]=arr[indx2];
                indx2++;
                continue;
            }
            if(indx2>r2) {
                tmp[i]=arr[indx1];
                indx1++;
                continue;
            }
            if(arr[indx1]<arr[indx2]) {
                tmp[i]=arr[indx1];
                indx1++;
                continue;
            }
            tmp[i]=arr[indx2];
            indx2++;
        }
        //Copying the elements of tmp into the main array
        for(int i=0,j=l1;i<tmp.length;i++,j++) {
            arr[j]=tmp[i];
        }
    }
    
    public static void sort(long arr[],int l,int r) {    //sort(arr,0,n-1);
        if(l==r) {
            return;
        }
        int mid=(l+r)/2;
        sort(arr,l,mid);
        sort(arr,mid+1,r);
        merge(arr,l,mid,mid+1,r);
    }
    public static void merge(long arr[],int l1,int r1,int l2,int r2) {
        long tmp[]=new long[r2-l1+1];
        int indx1=l1,indx2=l2;
        //sorting the two halves using a tmp array
        for(int i=0;i<tmp.length;i++) {
            if(indx1>r1) {
                tmp[i]=arr[indx2];
                indx2++;
                continue;
            }
            if(indx2>r2) {
                tmp[i]=arr[indx1];
                indx1++;
                continue;
            }
            if(arr[indx1]<arr[indx2]) {
                tmp[i]=arr[indx1];
                indx1++;
                continue;
            }
            tmp[i]=arr[indx2];
            indx2++;
        }
        //Copying the elements of tmp into the main array
        for(int i=0,j=l1;i<tmp.length;i++,j++) {
            arr[j]=tmp[i];
        }
    }
    
    static StringBuilder str;
    static int arr[],par[];
    static ArrayList<Integer> adj_lst[];
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        StringBuilder ans=new StringBuilder("");
        
        int k=input.scanInt();
        str=new StringBuilder(input.scanString());
        arr=new int[str.length()];
        adj_lst=new ArrayList[str.length()];
        for(int i=0;i<adj_lst.length;i++) {
            adj_lst[i]=new ArrayList<>();
        }
        
        int strt=0,diff=(int)Math.pow(2, k),cnt=0;
        for(int i=0;i<str.length()-1;i+=2) {
            if(i==strt) {
                diff/=2;
                strt=i+diff;
                cnt=0;
            }
            
            
            adj_lst[i].add(strt+cnt);
            adj_lst[strt+cnt].add(i);
            
            adj_lst[i+1].add(strt+cnt);
            adj_lst[strt+cnt].add(i+1);
            
            
            cnt++;
        }
        
        par=new int[str.length()];
        
        DFS(str.length()-1,-1);
        
//        for(int i=0;i<str.length();i++) {
//            System.out.print(arr[i]+" ");
//        }
//        System.out.println();
        
        int q=input.scanInt();
        
        char prev='.';
        
        for(int qq=0;qq<q;qq++) {
            
            
            
            int root=input.scanInt()-1;
            prev=str.charAt(root);
            str.setCharAt(root, input.scanString().charAt(0));
            int tr=root;
            
            if(adj_lst[root].size()==1) {
                if(str.charAt(root)=='0' || str.charAt(root)=='1') {
                    arr[root]=1;
                }
                else {
                    arr[root]=2;
                }
                root=par[root];
            }
            
            while(root!=-1) {
                
//                System.out.println(root);
                
                int val[]=new int[2];
                int indx[]=new int[2];
                cnt=0;
                for(int i=0;i<adj_lst[root].size();i++) {
                    if(adj_lst[root].get(i)==par[root]) {
                        continue;
                    }
                    
//                    System.out.println(root+" "+adj_lst[root].get(i)+" "+par[root]);
                    indx[cnt]=adj_lst[root].get(i);
                    val[cnt]=arr[adj_lst[root].get(i)];
                    cnt++;
                }
                
                int ret=0;
        
                if(str.charAt(root)=='0') {
                    if(indx[0]<indx[1]) {
                        ret=val[0];
                    }
                    else {
                        ret=val[1];
                    }
                }
                else if(str.charAt(root)=='1'){
                    if(indx[0]>indx[1]) {
                        ret=val[0];
                    }
                    else {
                        ret=val[1];
                    }
                }
                else {
                    ret=val[0]+val[1];
                }
                

                arr[root]=ret;
                
                root=par[root];
            }
//            System.out.println(qq);
            
            if(str.length()==1) {
                if(str.charAt(0)=='0' || str.charAt(0)=='1') {
                    arr[0]=1;
                }
                else {
                    arr[0]=2;
                }
            }
            
            ans.append(arr[str.length()-1]+"\n");
            
//            str.setCharAt(tr, prev);
            
        }
        
        System.out.println(ans);
    }
    
    public static int DFS(int root,int parent) {
        par[root]=parent;
        if(adj_lst[root].size()==1) {
            if(str.charAt(root)=='0' || str.charAt(root)=='1') {
                arr[root]=1;
                return 1;
            }
            arr[root]=2;
            return 2;
        }
        
        int val[]=new int[2];
        int indx[]=new int[2];
        for(int i=0,cnt=0;i<adj_lst[root].size();i++) {
            if(adj_lst[root].get(i)==parent) {
                continue;
            }
            
            indx[cnt]=adj_lst[root].get(i);
            val[cnt]=DFS(adj_lst[root].get(i),root);
            cnt++;
        }
        
        int ret=0;
        
        if(str.charAt(root)=='0') {
            if(indx[0]<indx[1]) {
                ret=val[0];
            }
            else {
                ret=val[1];
            }
        }
        else if(str.charAt(root)=='1'){
            if(indx[0]>indx[1]) {
                ret=val[0];
            }
            else {
                ret=val[1];
            }
        }
        else {
            ret=val[0]+val[1];
        }
        
        
        
        arr[root]=ret;
        return ret;
        
    }
}
