Recently Lynyrd and Skynyrd went to a shop where Lynyrd bought a permutation p of length n, and Skynyrd bought an array a of length m, consisting of integers from 1 to n. 

Lynyrd and Skynyrd became bored, so they asked you q queries, each of which has the following form: "does the subsegment of a from the l-th to the r-th positions, inclusive, have a subsequence that is a cyclic shift of p?" Please answer the queries.

A permutation of length n is a sequence of n integers such that each integer from 1 to n appears exactly once in it.

A cyclic shift of a permutation (p_1, p_2, …, p_n) is a permutation (p_i, p_{i + 1}, …, p_{n}, p_1, p_2, …, p_{i - 1}) for some i from 1 to n. For example, a permutation (2, 1, 3) has three distinct cyclic shifts: (2, 1, 3), (1, 3, 2), (3, 2, 1).

A subsequence of a subsegment of array a from the l-th to the r-th positions, inclusive, is a sequence a_{i_1}, a_{i_2}, …, a_{i_k} for some i_1, i_2, …, i_k such that l ≤ i_1 < i_2 < … < i_k ≤ r.

Input

The first line contains three integers n, m, q (1 ≤ n, m, q ≤ 2 ⋅ 10^5) — the length of the permutation p, the length of the array a and the number of queries.

The next line contains n integers from 1 to n, where the i-th of them is the i-th element of the permutation. Each integer from 1 to n appears exactly once.

The next line contains m integers from 1 to n, the i-th of them is the i-th element of the array a.

The next q lines describe queries. The i-th of these lines contains two integers l_i and r_i (1 ≤ l_i ≤ r_i ≤ m), meaning that the i-th query is about the subsegment of the array from the l_i-th to the r_i-th positions, inclusive.

Output

Print a single string of length q, consisting of 0 and 1, the digit on the i-th positions should be 1, if the subsegment of array a from the l_i-th to the r_i-th positions, inclusive, contains a subsequence that is a cyclic shift of p, and 0 otherwise.

Examples

Input

3 6 3
2 1 3
1 2 3 1 2 3
1 5
2 6
3 5


Output

110


Input

2 4 3
2 1
1 1 2 2
1 2
2 3
3 4


Output

010

Note

In the first example the segment from the 1-st to the 5-th positions is 1, 2, 3, 1, 2. There is a subsequence 1, 3, 2 that is a cyclic shift of the permutation. The subsegment from the 2-nd to the 6-th positions also contains a subsequence 2, 1, 3 that is equal to the permutation. The subsegment from the 3-rd to the 5-th positions is 3, 1, 2, there is only one subsequence of length 3 (3, 1, 2), but it is not a cyclic shift of the permutation.

In the second example the possible cyclic shifts are 1, 2 and 2, 1. The subsegment from the 1-st to the 2-nd positions is 1, 1, its subsequences are not cyclic shifts of the permutation. The subsegment from the 2-nd to the 3-rd positions is 1, 2, it coincides with the permutation. The subsegment from the 3 to the 4 positions is 2, 2, its subsequences are not cyclic shifts of the permutation.
import java.io.*;
import java.util.*;

public class E549 {
	public static void main(String[] args) { new E549(); }
	FS in = new FS();
	PrintWriter out = new PrintWriter(System.out);

	int n, m, q, log = 18;
	int[] p, a, bef;
	int[] deg, walk[];
	ArrayList<Integer>[] adj;
	TreeSet<Integer>[] idx;

	E549() {
		n = in.nextInt();
		m = in.nextInt();
		q = in.nextInt();

		p = new int[n];
		bef = new int[n + 1];
		for (int i = 0; i < n; i++) {
			p[i] = in.nextInt();
			if (i > 0) bef[p[i]] = p[i - 1];
		}
		bef[p[0]] = p[n - 1];

		a = new int[m];
		idx = new TreeSet[n + 1];
		for (int i = 0; i <= n; i++) idx[i] = new TreeSet<>();
		for (int i = 0; i < m; i++) {
			a[i] = in.nextInt();
			idx[a[i]].add(i);
		}
		
		deg = new int[m];
		adj = new ArrayList[m];
		for (int i = 0; i < m; i++) adj[i] = new ArrayList<>();
		for (int i = 0; i < m; i++) {
			Integer j = idx[bef[a[i]]].lower(i);
			if (j == null) continue;
			adj[j].add(i);
			deg[i]++;
		}
		
		walk = new int[log][m];
		ArrayDeque<Integer> Q = new ArrayDeque<>();
		for (int i = 0; i < m; i++) if (deg[i] == 0) Q.add(i);
		for (int i = 0; i < log; i++) Arrays.fill(walk[i], -1);
		while (Q.size() > 0) {
			int node = Q.poll();
			for (int i : adj[node]) {
				walk[0][i] = node;
				Q.add(i);
			}
		}

		for (int lg = 0; lg < log - 1; ++lg) {
			for (int i = 0; i < m; ++i) {
				if (walk[lg][i] != -1) {
					walk[lg + 1][i] = walk[lg][walk[lg][i]];
				}
			}
		}

		int[] near = new int[m];
		Arrays.fill(near, -1);
		for (int i = 0; i < m; i++) {
			int j = i;
			for (int k = log - 1; k >= 0; k--) {
				if (((1 << k) & (n - 1)) > 0)
					j = walk[k][j];
				if (j == -1) break;
			}
			near[i] = j;
		}

		RMQ rmq = new RMQ(near);
		char[] ans = new char[q];
		for (int i = 0; i < q; i++) {
			int l = in.nextInt() - 1;
			int r = in.nextInt() - 1;
			int nearest = rmq.query(l, r);
			if (l <= nearest) ans[i] = '1';
			else ans[i] = '0';
		}
		out.println(new String(ans));
		out.close();
	}

	class RMQ {
		int sz, vs[], lift[][];
		RMQ (int[] vs) {
			this.vs = vs;
			sz = vs.length;
			int maxlog = Integer.numberOfTrailingZeros(Integer.highestOneBit(sz)) + 2;
			lift = new int[maxlog][sz];
			for (int i = 0; i < sz; i++) lift[0][i] = vs[i];
			int lr = 1;
			for (int lg = 1; lg < maxlog; lg++) {
				for (int i = 0; i < sz; i++) {
					lift[lg][i] = max(lift[lg - 1][i], lift[lg - 1][min(i + lr, sz - 1)]);
				}
				lr <<= 1;
			}
		}

		int query(int lo, int hi) {
			int r = hi - lo + 1;
			int e = Integer.highestOneBit(r);
			int lg = Integer.numberOfTrailingZeros(e);
			return max(lift[lg][lo], lift[lg][hi - e + 1]);
		}
	}
	
	int abs(int x) { if (x < 0) return -x; return x; }
	long abs(long x) { if (x < 0) return -x; return x; }
	int min(int a, int b) { if (a < b) return a; return b; }	
	int max(int a, int b) { if (a > b) return a; return b; }	
	long min(long a, long b) { if (a < b) return a; return b; }	
	long max(long a, long b) { if (a > b) return a; return b; }	
	int gcd(int a, int b) { while (b > 0) { a = b^(a^(b = a)); b %= a; } return a; }
	long gcd(long a, long b) { while (b > 0) { a = b^(a^(b = a)); b %= a; } return a; }
	long lcm(int a, int b) { return (((long) a) * b) / gcd(a, b); }
	long lcm(long a, long b) { return (a * b) / gcd(a, b); }

	void sort(int[] arr) {
		int sz = arr.length, j;
		Random r = new Random();
		for (int i = 0; i < sz; i++) {
			j = r.nextInt(i + 1);
			arr[i] = arr[j]^(arr[i]^(arr[j] = arr[i]));
		} Arrays.sort(arr);
	}

	class FS {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens()) {
				try { st = new StringTokenizer(br.readLine()); }
				catch (Exception e) {}
			} return st.nextToken();
		}
		int nextInt() { return Integer.parseInt(next()); }
		long nextLong() { return Long.parseLong(next()); }
		double nextDouble() { return Double.parseDouble(next()); }
	}
}

