public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder out = new StringBuilder();
		String line = "";
		while ((line = in.readLine()) != null && line.length() != 0) {
			int n = Integer.parseInt(line.trim());
			if (n == 0)
				break;
			dig = new D[n];
			int s = 0;
			for (int i = 0; i < n; i++) {
				int[] df = readInts(in.readLine().trim());
				int d = df[0], f = df[1];
				dig[i] = new D(s, s + f + 1, d, f);
				s += f + 3;
			}
			int m = Integer.parseInt(in.readLine().trim());
			for (int i = 0; i < m; i++) {
				int[] rc = readInts(in.readLine());
				int r = rc[0], c = rc[1];
				int d = upperBound(r);
				if (d < 0)
					out.append(".\n");
				else
					out.append(solve(dig[d].n, r - dig[d].s, c, dig[d].f) + "\n");
			}
		}
		System.out.print(out);
	}