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.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.InputMismatchException;
import java.util.List;

public class D {
	// author: Nagabhushan S Baddi - 18:35

	// PRIMARY VARIABLES
	private static int n, m, k, x, y;
	private static int[] a, b, p;
	private static long ans;
	private static int[][] id, dp;
	private static int idf;
	private static char[] s, t;
	private static HashMap<Integer, ArrayList<Integer>> g;
	private static HashMap<Integer, Integer> pLeft;
	private static HashMap<Integer, Integer> pRight;
	private static long[] count;

	// CONSTANTS
	private static final int MOD = (int) 1e9 + 7;
	private static final int[] dx = { -1, 1, 0, 0 };
	private static final int[] dy = { 0, 0, -1, 1 };
	private static final int MAX = Integer.MAX_VALUE;
	private static final int MIN = Integer.MIN_VALUE;
	private static final long MAXLONG = (long) 1e18;
	private static final long MINLONG = -(long) 1e18;

	public static void main(String[] args) {
		k = ini();
		s = ins().toCharArray();
		
		int n = (1<<k)-1;
		
		count = new long[n];
		g = findParent();
		
		
		dfs(n-1);
		
//		for(int i=0; i<n; i++) {
//			pd(i+" "+count[i]);
//		}
//		
		int q = ini();

		nextQuery:
		while(q-->0) {
			int p = ini()-1;
			String c = ins();
			
			s[p] = c.charAt(0);
			
			long carrier = 0;
			
			if (c.equals("?")) {
				carrier = getSumOfChild(p);
			} else if (c.equals("1")) {
				carrier = getRight(p);
			} else {
				carrier = getLeft(p);
			}
			
			count[p] = carrier;
			
//			pd("C "+carrier);
			
			int node = p;
			
			while(true) {
				if (!pLeft.containsKey(node) && !pRight.containsKey(node)) {
					break;
				}
//				pd("NODE "+node);
				
				boolean done = true;
				
				if (pLeft.containsKey(node)) {
					int parentNode = pLeft.get(node);
//					pd("LEFT");
//					pd("PARENTNODE "+parentNode);
					
					if (s[parentNode]=='0') {
						carrier = carrier;
					} else if (s[parentNode]=='1') {
						carrier = count[node+1];
						done = false;
					} else {
						carrier += count[node+1];
					}
					
					node = parentNode;
					count[node] = carrier;
//					pd("CARRIER "+carrier);
				} else {
					int parentNode = pRight.get(node);
//					pd("RIGHT");
//					pd("PARENTNODE "+parentNode);
					
					if (s[parentNode]=='0') {
						carrier = count[node-1];
						done = false;
					} else if (s[parentNode]=='1') {
						carrier = carrier;
					} else {
						carrier += count[node-1];
					}
					

					node = parentNode;
					count[node] = carrier;
//					pd("CARRIER "+carrier);
				}
				
				if (!done) {
					println(count[n-1]);
					continue nextQuery;
				}
			}
			
			println(carrier);
		}

		out.flush();
		out.close();

	}
	
	private static long getSumOfChild(int p) {
		if (g.get(p).size()==0) {
			return 2;
		} else {
			return count[g.get(p).get(0)]+count[g.get(p).get(1)];
		}
	}
	
	private static long getLeft(int p) {
		if (g.get(p).size()==0) {
			return 1;
		} else {
			return count[g.get(p).get(0)];
		}
	}
	
	private static long getRight(int p) {
		if (g.get(p).size()==0) {
			return 1;
		} else {
			return count[g.get(p).get(1)];
		}
	}
	
	private static void dfs(int u) {
		if (g.get(u).size()==0) {
//			count[u] = 1;
			if (s[u]=='0') {
				count[u] = 1;
			} else if (s[u]=='1') {
				count[u] = 1;
			} else {
				count[u] = 2;
			}
			return;
		}
		
		int left = g.get(u).get(0);
		int right = g.get(u).get(1);
		
		dfs(left);
		dfs(right);
		
		if (s[u]=='0') {
			count[u] = count[left];
		} else if (s[u]=='1') {
			count[u] = count[right];
		} else {
			count[u] = count[left]+count[right];
		}
	}
	
	private static HashMap<Integer, ArrayList<Integer>> findParent() {
		
		pLeft = new HashMap<>();
		pRight = new HashMap<>();
		
		HashMap<Integer, ArrayList<Integer>> g = new HashMap<>();
		for(int i=0; i<(1<<k)-1; i++) {
			g.put(i, new ArrayList<>());
		}
		
		List<Integer> prev = new ArrayList<>();
		int count = 0;
		for(int i=0; i<(1<<(k-1)); i++) {
			prev.add(i);
			count++;
		}
		
		for(int j=0; j<k-1; j++) {
			
			List<Integer> nextPrev = new ArrayList<>();
			
			for(int k=0; k<prev.size(); k+=2) {
				int parent = count;
				
				g.get(parent).add(prev.get(k));
				g.get(parent).add(prev.get(k+1));
				
//				g.get(prev.get(k)).add(parent);
//				g.get(prev.get(k+1)).add(parent);
				pLeft.put(prev.get(k), parent);
				pRight.put(prev.get(k+1), parent);
				
				count++;
				
				nextPrev.add(parent);
			}
			
			prev = nextPrev;
		}
		
//		for(int x: g.keySet()) {
//			print(x+": ");
//			for(int y: g.get(x)) {
//				print(y+" ");
//			}
//			println();
//		}
		
		return g;
	}
	
	//(mid+1
	
	//1+2+2^2+...2^(f) (k/2)
	//2^(f+1)-1
	
//	2^f = k/2
			
//	k-1
//	
//	2^(z-1)  = 

	// INIT
	private static void initCase(int z) {
		idf = z;
		ans = 0;
	}

	// PRINT ANSWER
	private static void printAns(Object o) {
		out.println(o);
	}

	private static void printAns(Object o, int testCaseNo) {
		out.println("Case #" + testCaseNo + ": " + o);
	}

	private static void printArray(Object[] a) {
		for (int i = 0; i < a.length; i++) {
			out.print(a[i] + " ");
		}
		out.println();
	}

	// SORT SHORTCUTS - QUICK SORT TO MERGE SORT
	private static void sort(int[] a) {
		int n = a.length;
		Integer[] b = new Integer[n];
		for (int i = 0; i < n; i++) {
			b[i] = a[i];
		}

		Arrays.sort(b);

		for (int i = 0; i < n; i++) {
			a[i] = b[i];
		}
	}

	private static void sort(long[] a) {
		int n = a.length;
		Long[] b = new Long[n];
		for (int i = 0; i < n; i++) {
			b[i] = a[i];
		}

		Arrays.sort(b);

		for (int i = 0; i < n; i++) {
			a[i] = b[i];
		}
	}

	// INPUT SHORTCUTS

	private static int[] ina(int n) {
		int[] temp = new int[n];
		for (int i = 0; i < n; i++) {
			temp[i] = in.nextInt();
		}
		return temp;
	}

	private static int[][] ina2d(int n, int m) {
		int[][] temp = new int[n][m];
		for (int i = 0; i < n; i++) {
			temp[i] = ina(m);
		}
		return temp;
	}

	private static char[][] ina2dChar(int n, int m) {
		char[][] temp = new char[n][];
		for (int i = 0; i < n; i++) {
			temp[i] = ins().toCharArray();
		}
		return temp;
	}

	private static int ini() {
		return in.nextInt();
	}

	private static long inl() {
		return in.nextLong();
	}

	private static double ind() {
		return Double.parseDouble(ins());
	}

	private static String ins() {
		return in.readString();
	}

	// PRINT SHORTCUTS
	private static void println(Object... o) {
		for (Object x : o) {
			out.write(x + "");
		}
		out.write("\n");
	}

	private static void pd(Object... o) {
		for (Object x : o) {
			out.write(x + "");
		}
		out.flush();
		out.write("\n");
	}

	private static void print(Object... o) {
		for (Object x : o) {
			out.write(x + "");
		}
	}

	// GRAPH SHORTCUTS
	private static HashMap<Integer, ArrayList<Integer>> intree(int n) {

		HashMap<Integer, ArrayList<Integer>> g = new HashMap<>();
		for (int i = 0; i < n; i++) {
			g.put(i, new ArrayList<>());
		}

		for (int i = 0; i < n - 1; i++) {
			int u = ini() - 1;
			int v = ini() - 1;
			g.get(u).add(v);
			g.get(v).add(u);
		}

		return g;
	}

	private static HashMap<Integer, ArrayList<Integer>> ingraph(int n, int m) {
		HashMap<Integer, ArrayList<Integer>> g = new HashMap<>();

		for (int i = 0; i < n; i++) {
			g.put(i, new ArrayList<>());
		}

		for (int i = 0; i < m; i++) {
			int u = ini() - 1;
			int v = ini() - 1;
			g.get(u).add(v);
			g.get(v).add(u);
		}

		return g;

	}

	private static HashMap<Integer, ArrayList<Integer>> indirectedgraph(int n, int m) {
		HashMap<Integer, ArrayList<Integer>> g = new HashMap<>();

		for (int i = 0; i < n; i++) {
			g.put(i, new ArrayList<>());
		}

		for (int i = 0; i < m; i++) {
			int u = ini() - 1;
			int v = ini() - 1;
			g.get(u).add(v);
		}

		return g;

	}

	private static HashMap<Integer, ArrayList<Edge>> inweightedgraph(int n, int m) {
		HashMap<Integer, ArrayList<Edge>> g = new HashMap<>();

		for (int i = 0; i < n; i++) {
			g.put(i, new ArrayList<>());
		}

		for (int i = 0; i < m; i++) {
			int u = ini() - 1;
			int v = ini() - 1;
			int w = ini();
			Edge edge = new Edge(u, v, w);
			g.get(u).add(edge);
			g.get(v).add(edge);
		}

		return g;

	}

	private static class Edge implements Comparable<Edge> {
		private int u, v;
		private long w;

		public Edge(int a, int b, long c) {
			u = a;
			v = b;
			w = c;
		}

		public int other(int x) {
			return (x == u ? v : u);
		}

		public int compareTo(Edge edge) {
			return Long.compare(w, edge.w);
		}
	}

	private static class Pair {
		private int u, v;

		public Pair(int a, int b) {
			u = a;
			v = b;
		}

		public int hashCode() {
			return u + v + u * v;
		}

		public boolean equals(Object object) {
			Pair pair = (Pair) object;
			return u == pair.u && v == pair.v;
		}
	}

	private static class Triplet {
		private int u, v, w;

		public Triplet(int a, int b, int c) {
			u = a;
			v = b;
			w = c;
		}

		public int hashCode() {
			return u + v + w + u * v + v * w + u * w + u * v * w;
		}

		public boolean equals(Object object) {
			Triplet triplet = (Triplet) object;
			return u == triplet.u && v == triplet.v && v == triplet.w;
		}
	}

	private static class Node implements Comparable<Node> {
		private int u;
		private long dist;

		public Node(int a, long b) {
			u = a;
			dist = b;
		}

		public int compareTo(Node node) {
			return Long.compare(dist, node.dist);
		}
	}

	// MATHS AND NUMBER THEORY SHORTCUTS
	private static int gcd(int a, int b) {
		// O(log(min(a,b)))
		if (b == 0)
			return a;

		return gcd(b, a % b);
	}

	private static long modExp(long a, long b) {
		if (b == 0)
			return 1;

		a %= MOD;

		long exp = modExp(a, b / 2);

		if (b % 2 == 0) {
			return (exp * exp) % MOD;
		} else {
			return (a * ((exp * exp) % MOD)) % MOD;
		}
	}

	private static long mul(int a, int b) {
		return a * 1L * b;
	}

	// Segment Tree
	private static class SegmentTree<T extends Comparable<T>> {
		private int n, m;
		private T[] a;
		private T[] seg;
		private T NULLVALUE;

		public SegmentTree(int n, T NULLVALUE) {
			this.NULLVALUE = NULLVALUE;
			this.n = n;
			m = 4 * n;
			seg = (T[]) new Object[m];

		}

		public SegmentTree(T[] a, int n, T NULLVALUE) {
			this.NULLVALUE = NULLVALUE;
			this.a = a;
			this.n = n;
			m = 4 * n;
			seg = (T[]) new Object[m];
			construct(0, n - 1, 0);
		}

		private void update(int pos) {
			// Range Sum
			// seg[pos] = seg[2*pos+1]+seg[2*pos+2];

			// Range Min
			if (seg[2 * pos + 1].compareTo(seg[2 * pos + 2]) <= 0) {
				seg[pos] = seg[2 * pos + 1];
			} else {
				seg[pos] = seg[2 * pos + 2];
			}
		}

		private T optimum(T leftValue, T rightValue) {
			// Range Sum
			// return leftValue+rightValue;

			// Range Min
			if (leftValue.compareTo(rightValue) <= 0) {
				return leftValue;
			} else {
				return rightValue;
			}
		}

		public void construct(int low, int high, int pos) {
			if (low == high) {
				seg[pos] = a[low];
				return;
			}

			int mid = (low + high) / 2;

			construct(low, mid, 2 * pos + 1);
			construct(mid + 1, high, 2 * pos + 2);
			update(pos);
		}

		public void add(int index, T value) {
			add(index, value, 0, n - 1, 0);
		}

		private void add(int index, T value, int low, int high, int pos) {
			if (low == high) {
				seg[pos] = value;
				return;
			}

			int mid = (low + high) / 2;

			if (index <= mid) {
				add(index, value, low, mid, 2 * pos + 1);
			} else {
				add(index, value, mid + 1, high, 2 * pos + 2);
			}
			update(pos);
		}

		public T get(int qlow, int qhigh) {
			return get(qlow, qhigh, 0, n - 1, 0);
		}

		public T get(int qlow, int qhigh, int low, int high, int pos) {
			if (qlow > low || low > qhigh) {
				return NULLVALUE;
			} else if (qlow <= low || qhigh >= high) {
				return seg[pos];
			} else {
				int mid = (low + high) / 2;
				T leftValue = get(qlow, qhigh, low, mid, 2 * pos + 1);
				T rightValue = get(qlow, qhigh, mid + 1, high, 2 * pos + 2);

				return optimum(leftValue, rightValue);
			}
		}
	}

	// DSU
	private static class DSU {
		private int[] id;
		private int[] size;
		private int n;

		public DSU(int n) {
			this.n = n;

			id = new int[n];
			for (int i = 0; i < n; i++) {
				id[i] = i;
			}

			size = new int[n];
			Arrays.fill(size, 1);
		}

		private int root(int u) {
			while (u != id[u]) {
				id[u] = id[id[u]];
				u = id[u];
			}
			return u;
		}

		public boolean connected(int u, int v) {
			return root(u) == root(v);
		}

		public void union(int u, int v) {
			int p = root(u);
			int q = root(v);

			if (size[p] >= size[q]) {
				id[q] = p;
				size[p] += size[q];
			} else {
				id[p] = q;
				size[q] += size[p];
			}
		}
	}

	// KMP
	private static int countSearch(String s, String p) {
		int n = s.length();
		int m = p.length();

		int[] b = backTable(p);

		int j = 0;
		int count = 0;

		for (int i = 0; i < n; i++) {
			if (j == m) {
				j = b[j - 1];
				count++;
			}
			while (j != 0 && s.charAt(i) != p.charAt(j)) {
				j = b[j - 1];
			}
			if (s.charAt(i) == p.charAt(j)) {
				j++;
			}
		}

		if (j == m)
			count++;

		return count;
	}

	private static int[] backTable(String p) {
		int m = p.length();

		int j = 0;
		int[] b = new int[m];

		for (int i = 1; i < m; i++) {
			while (j != 0 && p.charAt(i) != p.charAt(j)) {
				j = b[j - 1];
			}
			if (p.charAt(i) == p.charAt(j)) {
				b[i] = ++j;
			}
		}
		return b;
	}

	private static int[][] countMap(String s) {
		int n = s.length();

		int[][] map = new int[n][26];

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 26; j++) {
				map[i][j] = (i - 1 >= 0 ? map[i - 1][j] : 0);
			}
			map[i][s.charAt(i) - 'a']++;
		}

		return map;
	}

	private static int[][] rightOcc(String s) {
		int n = s.length();

		int[][] right = new int[n][26];

		for (int i = n - 1; i >= 0; i--) {
			for (int j = 0; j < 26; j++) {
				right[i][j] = (i + 1 < n ? right[i + 1][j] : -1);
			}
			right[i][s.charAt(i) - 'a'] = i;
		}

		return right;
	}

	private static int[][] leftOcc(String s) {
		int n = s.length();

		int[][] left = new int[n][26];

		for (int i = 0; i < n; i++) {
			for (int j = 0; j < 26; j++) {
				left[i][j] = (i - 1 >= 0 ? left[i - 1][j] : -1);
			}
			left[i][s.charAt(i) - 'a'] = i;
		}

		return left;
	}

	// LCA
	private static class LCA {
		private HashMap<Integer, ArrayList<Integer>> g;
		private int[] level;
		private int[] a;
		private int[][] P;
		private int n, m;
		private int[] xor;

		public LCA(HashMap<Integer, ArrayList<Integer>> g, int[] a) {
			this.g = g;
			this.a = a;
			n = g.size();
			m = (int) (Math.log(n) / Math.log(2)) + 5;
			P = new int[n][m];
			xor = new int[n];
			level = new int[n];

			preprocess();
		}

		private void preprocess() {
			dfs(0, -1);

			for (int j = 1; j < m; j++) {
				for (int i = 0; i < n; i++) {
					if (P[i][j - 1] != -1) {
						P[i][j] = P[P[i][j - 1]][j - 1];
					}
				}
			}
		}

		private void dfs(int u, int p) {
			P[u][0] = p;
			xor[u] = a[u] ^ (p == -1 ? 0 : xor[p]);
			level[u] = (p == -1 ? 0 : level[p] + 1);

			for (int v : g.get(u)) {
				if (v == p)
					continue;
				dfs(v, u);
			}
		}

		public int lca(int u, int v) {
			if (level[v] > level[u]) {
				int temp = v;
				v = u;
				u = temp;
			}

			for (int j = m; j >= 0; j--) {
				if (level[u] - (1 << j) < level[v]) {
					continue;
				} else {
					u = P[u][j];
				}
			}

			if (u == v)
				return u;

			for (int j = m - 1; j >= 0; j--) {
				if (P[u][j] == -1 || P[u][j] == P[v][j]) {
					continue;
				} else {
					u = P[u][j];
					v = P[v][j];
				}
			}

			return P[u][0];
		}

		private int xor(int u, int v) {
			int l = lca(u, v);

			return xor[u] ^ xor[v] ^ a[l];
		}
	}

	// Geometry
	private static class Line {
		private int a, b, c;

		public Line(int x1, int y1, int x2, int y2) {
			a = y2 - y1;
			b = x1 - x2;
			c = a * x1 + b * y1;

			int g = gcd(a, gcd(b, c));

			a /= g;
			b /= g;
			c /= g;
		}

		public int hashCode() {
			return a + b + c + a * b + b * c + c * a + a * b * c;
		}

		public boolean equals(Object o) {
			Line line = (Line) o;
			return a == line.a && b == line.b && c == line.c;
		}
	}

	// FAST INPUT OUTPUT LIBRARY
	private static InputReader in = new InputReader(System.in);
	private static PrintWriter out = new PrintWriter(System.out);

	private static class InputReader {

		private final InputStream stream;
		private final byte[] buf = new byte[8192];
		private int curChar, snumChars;

		public InputReader(InputStream st) {
			this.stream = st;
		}

		public int read() {
			if (snumChars == -1)
				throw new InputMismatchException();
			if (curChar >= snumChars) {
				curChar = 0;
				try {
					snumChars = stream.read(buf);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (snumChars <= 0)
					return -1;
			}
			return buf[curChar++];
		}

		public int nextInt() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			int res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public long nextLong() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			int sgn = 1;
			if (c == '-') {
				sgn = -1;
				c = read();
			}
			long res = 0;
			do {
				res *= 10;
				res += c - '0';
				c = read();
			} while (!isSpaceChar(c));
			return res * sgn;
		}

		public String readString() {
			int c = read();
			while (isSpaceChar(c)) {
				c = read();
			}
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isSpaceChar(c));
			return res.toString();
		}

		public String nextLine() {
			int c = read();
			while (isSpaceChar(c))
				c = read();
			StringBuilder res = new StringBuilder();
			do {
				res.appendCodePoint(c);
				c = read();
			} while (!isEndOfLine(c));
			return res.toString();
		}

		public boolean isSpaceChar(int c) {
			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
		}

		private boolean isEndOfLine(int c) {
			return c == '\n' || c == '\r' || c == -1;
		}

	}
}


