import java.io.*;
import java.util.*;

public class greedy_bm {
	FastScanner in;
	PrintWriter out;

	int[] c;
	int x;
	int MAX = 10;

	class SegmentTreeVertex {
		int left, right, length;
		int[] ansFrom;
		int[] lastFrom;
		SegmentTreeVertex l, r;

		public SegmentTreeVertex(int left, int right) {
			super();
			this.left = left;
			this.right = right;
			ansFrom = new int[MAX];
			lastFrom = new int[MAX];
			length = right - left + 1;
			for (int i = length; i < MAX; i++)
				ansFrom[i] = -1;
			if (left != right) {
				int m = (left + right) / 2;
				l = new SegmentTreeVertex(left, m);
				r = new SegmentTreeVertex(m + 1, right);
			}
			update();
		}

		private void update() {
			if (left == right) {
				ansFrom[0] = 1;
				lastFrom[0] = c[left];
				return;
			}
			int m = (left + right) / 2;
			int lenD2 = m - left + 1;
			for (int fr = 0; fr < Math.min(length, MAX - 1); fr++) {
				if (fr < lenD2) {
					int last = l.lastFrom[fr];
					int curAns = l.ansFrom[fr];
					for (int i = lenD2; i < length; i++) {
						if (last * 10L + c[left + i] > x) {
							ansFrom[fr] = curAns + r.ansFrom[i - lenD2];
							lastFrom[fr] = r.lastFrom[i - lenD2];
							last = -1;
							break;
						} else {
							last = last * 10 + c[left + i];
						}
					}
					if (last != -1) {
						ansFrom[fr] = curAns;
						lastFrom[fr] = last;
					}
				} else {
					ansFrom[fr] = r.ansFrom[fr - lenD2];
					lastFrom[fr] = r.lastFrom[fr - lenD2];
				}
			}
		}

		void updateResult(int pos) {
			if (left == right) {
				ansFrom[0] = 1;
				lastFrom[0] = c[pos];
			} else {
				int m = (left + right) / 2;
				if (pos <= m)
					l.updateResult(pos);
				else
					r.updateResult(pos);
				update();
			}
		}

	}

	void solve() {
		String s = in.next();
		c = new int[s.length()];
		for (int i = 0; i < s.length(); i++)
			c[i] = s.charAt(i) - '0';
		int m = in.nextInt();
		x = in.nextInt();

		SegmentTreeVertex root = new SegmentTreeVertex(0, s.length() - 1);
		out.println(root.ansFrom[0]);
		for (int i = 0; i < m; i++) {
			int pos = in.nextInt() - 1;
			c[pos] = in.nextInt();
			root.updateResult(pos);
			out.println(root.ansFrom[0]);
		}
	}

	void run() {
		try {
			in = new FastScanner(new File("greedy.in"));
			out = new PrintWriter(new File("greedy.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

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

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

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

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

	public static void main(String[] args) {
		new greedy_bm().run();
	}
}