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

public class greedy_vd_wa {

	int[][] ans;
	int[][] end;

	int[] seq;

	void buildtree(int l, int r, int i) {
		if (l == r) {
			ans[i][0] = 1;
			end[i][0] = seq[l];
			return;
		}
		buildtree(l, (l + r) / 2, i * 2);
		buildtree((l + r) / 2 + 1, r, i * 2 + 1);
		merge(l, r, i);
	}

	void update(int l, int r, int pos, int what, int i) {
		if (l == r) {
			ans[i][0] = 1;
			end[i][0] = what;
			seq[pos] = what;
			return;
		}
		if (pos <= (l + r) / 2) {
			update(l, (l + r) / 2, pos, what, i * 2);
		} else {
			update((l + r) / 2 + 1, r, pos, what, i * 2 + 1);
		}
		merge(l, r, i);
	}

	void merge(int l, int r, int i) {
		int x = (l + r) / 2;
		for (int j = 0; j < 9; j++) {
			if (x - l + 1 <= j) {
				ans[i][j] = ans[i * 2 + 1][j - (x - l + 1)];
				end[i][j] = end[i * 2 + 1][j - (x - l + 1)];
				continue;
			}
			ans[i][j] = ans[i * 2][j];
			int k = end[i * 2][j];
			int st = x + 1;
			int sum = 0;
			while (k <= up && st <= r) {
				k = k * 10 + seq[st];
				sum++;
				st++;
			}
			if (k > up) {
				k = k / 10;
				sum--;
				st--;
			}
			ans[i][j] += ans[i * 2 + 1][sum];
			end[i][j] = end[i * 2 + 1][sum];
			if (st > r) {
				end[i][j] = k;
			}
		}
	}

	int up;

	public void solve() throws IOException {
		long tm  = System.currentTimeMillis();
		String s = in.nextToken();
		int n = s.length();
		seq = new int[n + 1];
		for (int i = 0; i < n; i++) {
			seq[i + 1] = s.charAt(i) - '0';
		}
		int m = in.nextInt();
		up = in.nextInt();
		ans = new int[4 * n + 1][10];
		end = new int[4 * n + 1][10];
		buildtree(1, n, 1);
		out.println(ans[1][0]);
		for (int i = 0; i < m; i++) {
			update(1, n, in.nextInt(), in.nextInt(), 1);
			out.println(ans[1][0]);
		}
		System.err.println(System.currentTimeMillis()-tm);
	}

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

	FastScanner in;
	PrintWriter out;

	void run() {
		Locale.setDefault(Locale.US);
		try {
			in = new FastScanner("greedy".toLowerCase() + ".in");
			out = new PrintWriter("greedy".toLowerCase() + ".out");
			solve();
			out.close();
		} catch (IOException e) {
			e.printStackTrace();
		}

	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer str;

		public FastScanner(String file) throws FileNotFoundException {
			if (file == null) {
				br = new BufferedReader(new InputStreamReader(System.in));
			} else {
				br = new BufferedReader(new FileReader(file));
			}
		}

		public String nextToken() throws IOException {
			String cur;
			while (str == null || !str.hasMoreTokens()) {
				cur = br.readLine();
				if (cur == null) {
					return null;
				}
				str = new StringTokenizer(cur);
			}
			return str.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(nextToken());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(nextToken());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(nextToken());
		}

	}
}
