#include<bits/stdc++.h>
using namespace std;
#define int long long
int ans[300010],pw[20],s1[300010],s2[300010],fa[300010];
string s;
void solve(int x)
{
	if(!s1[x])
	{
		if(s[x]=='?')
			ans[x]=2;
		else
			ans[x]=1;
		return;
	}
	solve(s1[x]);
	solve(s2[x]);
	if(s[x]=='?')
		ans[x]=ans[s1[x]]+ans[s2[x]];
	else
		if(s[x]=='0')
			ans[x]=ans[s1[x]];
		else
			ans[x]=ans[s2[x]];
}
signed main()
{
	int k,i,j,t,q,sum=0;
	char c;
	cin>>k>>s>>q;
	s="#"+s;
	if(k==1)
	{
		while(q--)
		{
			cin>>t>>c;
			if(c=='?')
				puts("2");
			else
				puts("1");
		}
		return 0;
	}
	pw[0]=1;
	for(i=1;i<=k;i++)
		pw[i]=pw[i-1]*2;
	vector<int>v;
	for(i=1;i<=pw[k-1];i++)
		v.push_back(i),sum++;
	for(i=k-2;i;i--)
	{
		vector<int>v2;
		for(j=0;j<pw[i];j++)
		{
			sum++;
			s1[sum]=v[j*2];
			s2[sum]=v[j*2+1];
			fa[v[j*2]]=sum;
			fa[v[j*2+1]]=sum;
			v2.push_back(sum);
		}
		v=v2;
	}
	s1[pw[k]-1]=pw[k]-3;
	s2[pw[k]-1]=pw[k]-2;
	fa[pw[k]-3]=fa[pw[k]-2]=pw[k]-1;
	solve(pw[k]-1);
	while(q--)
	{
		cin>>t>>c;
		s[t]=c;
		for(;t;t=fa[t])
		{
			int x=t;
			if(!s1[x])
			{
				if(s[x]=='?')
					ans[x]=2;
				else
					ans[x]=1;
			}
			else
			{
				if(s[x]=='?')
					ans[x]=ans[s1[x]]+ans[s2[x]];
				else
					if(s[x]=='0')
						ans[x]=ans[s1[x]];
					else
						ans[x]=ans[s2[x]];
			}
		}
		cout<<ans[pw[k]-1]<<endl;
	}
	return 0;
}
