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.
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
struct fast_ios {
  fast_ios() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  };
} fast_ios_;
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto v : vec) os << v << ",";
  os << "]";
  return os;
}
int N, M, Q;
vector<int> P, A;
vector<int> prv_val;
vector<vector<int>> nx;
template <typename T>
struct SegTree {
  int N;
  int head;
  vector<T> x;
  T defaultT;
  using func = function<T(const T &, const T &)>;
  func merger;
  T _get(int begin, int end, int pos, int l, int r) const {
    if (r <= begin or l >= end) return defaultT;
    if (l >= begin and r <= end) return x[pos];
    return merger(_get(begin, end, 2 * pos + 1, l, (l + r) / 2),
                  _get(begin, end, 2 * pos + 2, (l + r) / 2, r));
  }
  SegTree(int N, T defaultT, func merger)
      : N(N), defaultT(defaultT), merger(merger) {
    int N_tmp = 1;
    while (N_tmp < N) N_tmp <<= 1;
    x.assign(N_tmp * 2, defaultT), head = N_tmp - 1;
  }
  SegTree(const vector<T> &vals, T defaultT, func merger)
      : N(vals.size()), defaultT(defaultT), merger(merger) {
    int N_tmp = 1;
    while (N_tmp < N) N_tmp <<= 1;
    x.assign(N_tmp * 2, defaultT), head = N_tmp - 1;
    copy(vals.begin(), vals.end(), x.begin() + head);
    for (int i = (head)-1, i_begin_ = (0); i >= i_begin_; i--)
      x[i] = merger(x[i * 2 + 1], x[i * 2 + 2]);
  }
  SegTree() : SegTree(0, T(), [](T, T) { return T(); }) {}
  void build(const vector<T> &vals) {
    copy(vals.begin(), vals.end(), x.begin() + head);
    for (int i = (head)-1, i_begin_ = (0); i >= i_begin_; i--)
      x[i] = merger(x[i * 2 + 1], x[i * 2 + 2]);
  }
  void update(int pos, T val) {
    pos += head, x[pos] = val;
    while (pos)
      pos = (pos - 1) / 2, x[pos] = merger(x[pos * 2 + 1], x[pos * 2 + 2]);
  }
  T get(int begin, int end) const {
    return _get(begin, end, 0, 0, (int)x.size() / 2);
  }
  friend ostream &operator<<(ostream &os, const SegTree<T> &s) {
    os << "[";
    for (int i = (0), i_end_ = (s.N); i < i_end_; i++)
      os << s.get(i, i + 1) << ",";
    os << "]";
    return os;
  }
};
struct Doubling {
  int N, LN;
  vector<vector<int>> mat;
  Doubling() : N(0), LN(0) {}
  Doubling(const vector<int> vec_nxt, int INVALID = -1) : N(vec_nxt.size()) {
    LN = 1;
    while (1 << LN < N) LN++;
    mat.assign(LN, vector<int>(N, INVALID));
    mat[0] = vec_nxt;
    for (int d = (0), d_end_ = (LN - 1); d < d_end_; d++)
      for (int i = (0), i_end_ = (N); i < i_end_; i++)
        if (mat[d][i] >= 0 and mat[d][i] < N) {
          mat[d + 1][i] = mat[d][mat[d][i]];
        }
  }
  int kth_forward(int now, int len) {
    for (int d = 0; len and now >= 0 and now < N; d++, len >>= 1) {
      if (len & 1) now = mat[d][now];
    }
    return now;
  }
};
int main() {
  cin >> N >> M >> Q;
  P.resize(N), A.resize(M);
  for (int i = (0), i_end_ = (N); i < i_end_; i++) cin >> P[i];
  for (int i = (0), i_end_ = (M); i < i_end_; i++) cin >> A[i];
  prv_val.resize(N + 1);
  for (int i = (0), i_end_ = (N); i < i_end_; i++)
    prv_val[P[(i + 1) % P.size()]] = P[i];
  vector<int> nxt1(M, M);
  map<int, vector<int>> ma;
  for (int i = (0), i_end_ = (M); i < i_end_; i++) {
    int a = A[i], prva = prv_val[a];
    for (auto v : ma[prva]) nxt1[v] = i;
    ma.erase(prva);
    ma[a].push_back(i);
  }
  Doubling dbl(nxt1, M);
  vector<int> r(M);
  for (int i = (0), i_end_ = (M); i < i_end_; i++) {
    int to = dbl.kth_forward(i, N - 1);
    r[i] = to;
  }
  SegTree<int> rmq(r, 1e9, [](int a, int b) { return min(a, b); });
  string ans;
  for (int _ = (0), __end_ = (Q); _ < __end_; _++) {
    int l, r;
    cin >> l >> r;
    int q = rmq.get(l - 1, r);
    if (q < r)
      ans += "1";
    else
      ans += "0";
  }
  cout << ans << endl;
}
