#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long powmod(long long a, long long b, long long MOD) {
  a %= MOD;
  if (a == 0ll) {
    return 0ll;
  }
  long long ans = 1;
  while (b) {
    if (b & 1) {
      ans = ans * a % MOD;
    }
    a = a * a % MOD;
    b >>= 1;
  }
  return ans;
}
void Pv(const vector<int> &V) {
  int Len = int(V.size());
  for (int i = 0; i < Len; ++i) {
    printf("%d", V[i]);
    if (i != Len - 1) {
      printf(" ");
    } else {
      printf("\n");
    }
  }
}
void Pvl(const vector<long long> &V) {
  int Len = int(V.size());
  for (int i = 0; i < Len; ++i) {
    printf("%lld", V[i]);
    if (i != Len - 1) {
      printf(" ");
    } else {
      printf("\n");
    }
  }
}
inline void getInt(int *p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
int op;
int n;
const int maxL = 3000010;
long long tree[maxL];
int lowbit(int x) { return -x & x; }
long long ask(int x) {
  long long res = 0ll;
  while (x) {
    res += tree[x];
    x -= lowbit(x);
  }
  return res;
}
void add(int x, long long val) {
  while (x < maxL) {
    tree[x] += val;
    x += lowbit(x);
  }
}
void bitclear(int x) {
  while (x != 0 && x < maxL) {
    tree[x] = 0;
    x += lowbit(x);
  }
}
struct node {
  int t;
  int op;
  int x, y;
  int k;
  int val;
  node() {}
  node(int tt, int oo, int xx, int yy, int kk, int vv) {
    t = tt;
    op = oo;
    x = xx;
    y = yy;
    k = kk;
    val = vv;
  }
  bool operator<(const node &bb) const {
    if (x != bb.x) {
      return x < bb.x;
    } else {
      return y <= bb.y;
    }
  }
};
node a[maxn];
node b[maxn];
long long ans[maxn];
int tot;
int anstot;
void cdq(int l, int r) {
  if (l == r) {
    return;
  }
  int mid = (l + r) >> 1;
  cdq(l, mid);
  cdq(mid + 1, r);
  int ql = l;
  int qr = mid + 1;
  if (l == 1 && r > 10) {
    l = 1;
  }
  for (int i = l; i <= r; i++) {
    if (qr > r || (ql <= mid && a[ql] < a[qr])) {
      if (a[ql].op == 1) {
        add(a[ql].y, a[ql].val);
      }
      b[i] = a[ql++];
    } else {
      if (a[qr].op == 2) {
        ans[a[qr].val] += a[qr].k * ask(a[qr].y);
      }
      b[i] = a[qr++];
    }
  }
  ql = l;
  qr = mid + 1;
  for (int i = l; i <= r; i++) {
    bitclear(b[i].y);
    a[i] = b[i];
  }
}
int aa[maxn];
int bb[maxn];
int pos[maxn];
int mpp[maxn];
int main() {
  int n, m;
  scanf("%d %d", &(n), &(m));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &(aa[i]));
    ;
    pos[aa[i]] = i;
  }
  int x, y, c;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &(bb[i]));
    ;
    x = i;
    y = pos[bb[i]];
    mpp[x] = y;
    tot++;
    a[tot] = node(tot, 1, x, y, 0, 1);
  }
  int x11, y11;
  while (m--) {
    scanf("%d", &op);
    if (op == 2) {
      scanf("%d %d", &(x), &(y));
      tot++;
      a[tot] = node(tot, 1, x, mpp[x], 0, -1);
      tot++;
      a[tot] = node(tot, 1, y, mpp[y], 0, -1);
      swap(mpp[x], mpp[y]);
      tot++;
      a[tot] = node(tot, 1, x, mpp[x], 0, 1);
      tot++;
      a[tot] = node(tot, 1, y, mpp[y], 0, 1);
    } else if (op == 1) {
      int l1, r1, l2, r2;
      scanf("%d %d", &(l2), &(r2));
      scanf("%d %d", &(l1), &(r1));
      tot++;
      a[tot] = node(tot, 2, l1 - 1, l2 - 1, 1, ++anstot);
      tot++;
      a[tot] = node(tot, 2, l1 - 1, r2, -1, anstot);
      tot++;
      a[tot] = node(tot, 2, r1, l2 - 1, -1, anstot);
      tot++;
      a[tot] = node(tot, 2, r1, r2, 1, anstot);
    }
  }
  cdq(1, tot);
  for (int i = 1; i <= anstot; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}
inline void getInt(int *p) {
  char ch;
  do {
    ch = getchar();
  } while (ch == ' ' || ch == '\n');
  if (ch == '-') {
    *p = -(getchar() - '0');
    while ((ch = getchar()) >= '0' && ch <= '9') {
      *p = *p * 10 - ch + '0';
    }
  } else {
    *p = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9') {
      *p = *p * 10 + ch - '0';
    }
  }
}

### Prompt

Generate a cpp solution to the following problem:

You are given two permutations a and b, both consisting of n elements. Permutation of n elements is such a integer sequence that each value from 1 to n appears exactly once in it.

You are asked to perform two types of queries with them:

  * 1~l_a~r_a~l_b~r_b — calculate the number of values which appear in both segment [l_a; r_a] of positions in permutation a and segment [l_b; r_b] of positions in permutation b; 
  * 2~x~y — swap values on positions x and y in permutation b. 



Print the answer for each query of the first type.

It is guaranteed that there will be at least one query of the first type in the input.

Input

The first line contains two integers n and m (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ m ≤ 2 ⋅ 10^5) — the number of elements in both permutations and the number of queries.

The second line contains n integers a_1, a_2, ..., a_n (1 ≤ a_i ≤ n) — permutation a. It is guaranteed that each value from 1 to n appears in a exactly once.

The third line contains n integers b_1, b_2, ..., b_n (1 ≤ b_i ≤ n) — permutation b. It is guaranteed that each value from 1 to n appears in b exactly once.

Each of the next m lines contains the description of a certain query. These are either:

  * 1~l_a~r_a~l_b~r_b (1 ≤ l_a ≤ r_a ≤ n, 1 ≤ l_b ≤ r_b ≤ n); 
  * 2~x~y (1 ≤ x, y ≤ n, x ≠ y). 

Output

Print the answers for the queries of the first type, each answer in the new line — the number of values which appear in both segment [l_a; r_a] of positions in permutation a and segment [l_b; r_b] of positions in permutation b.

Example

Input


6 7
5 1 4 2 3 6
2 5 3 1 4 6
1 1 2 4 5
2 2 4
1 1 2 4 5
1 2 3 3 5
1 1 6 1 2
2 4 1
1 4 4 1 3


Output


1
1
1
2
0

Note

Consider the first query of the first example. Values on positions [1; 2] of a are [5, 1] and values on positions [4; 5] of b are [1, 4]. Only value 1 appears in both segments.

After the first swap (the second query) permutation b becomes [2, 1, 3, 5, 4, 6].

After the second swap (the sixth query) permutation b becomes [5, 1, 3, 2, 4, 6].

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long powmod(long long a, long long b, long long MOD) {
  a %= MOD;
  if (a == 0ll) {
    return 0ll;
  }
  long long ans = 1;
  while (b) {
    if (b & 1) {
      ans = ans * a % MOD;
    }
    a = a * a % MOD;
    b >>= 1;
  }
  return ans;
}
void Pv(const vector<int> &V) {
  int Len = int(V.size());
  for (int i = 0; i < Len; ++i) {
    printf("%d", V[i]);
    if (i != Len - 1) {
      printf(" ");
    } else {
      printf("\n");
    }
  }
}
void Pvl(const vector<long long> &V) {
  int Len = int(V.size());
  for (int i = 0; i < Len; ++i) {
    printf("%lld", V[i]);
    if (i != Len - 1) {
      printf(" ");
    } else {
      printf("\n");
    }
  }
}
inline void getInt(int *p);
const int maxn = 1000010;
const int inf = 0x3f3f3f3f;
int op;
int n;
const int maxL = 3000010;
long long tree[maxL];
int lowbit(int x) { return -x & x; }
long long ask(int x) {
  long long res = 0ll;
  while (x) {
    res += tree[x];
    x -= lowbit(x);
  }
  return res;
}
void add(int x, long long val) {
  while (x < maxL) {
    tree[x] += val;
    x += lowbit(x);
  }
}
void bitclear(int x) {
  while (x != 0 && x < maxL) {
    tree[x] = 0;
    x += lowbit(x);
  }
}
struct node {
  int t;
  int op;
  int x, y;
  int k;
  int val;
  node() {}
  node(int tt, int oo, int xx, int yy, int kk, int vv) {
    t = tt;
    op = oo;
    x = xx;
    y = yy;
    k = kk;
    val = vv;
  }
  bool operator<(const node &bb) const {
    if (x != bb.x) {
      return x < bb.x;
    } else {
      return y <= bb.y;
    }
  }
};
node a[maxn];
node b[maxn];
long long ans[maxn];
int tot;
int anstot;
void cdq(int l, int r) {
  if (l == r) {
    return;
  }
  int mid = (l + r) >> 1;
  cdq(l, mid);
  cdq(mid + 1, r);
  int ql = l;
  int qr = mid + 1;
  if (l == 1 && r > 10) {
    l = 1;
  }
  for (int i = l; i <= r; i++) {
    if (qr > r || (ql <= mid && a[ql] < a[qr])) {
      if (a[ql].op == 1) {
        add(a[ql].y, a[ql].val);
      }
      b[i] = a[ql++];
    } else {
      if (a[qr].op == 2) {
        ans[a[qr].val] += a[qr].k * ask(a[qr].y);
      }
      b[i] = a[qr++];
    }
  }
  ql = l;
  qr = mid + 1;
  for (int i = l; i <= r; i++) {
    bitclear(b[i].y);
    a[i] = b[i];
  }
}
int aa[maxn];
int bb[maxn];
int pos[maxn];
int mpp[maxn];
int main() {
  int n, m;
  scanf("%d %d", &(n), &(m));
  for (int i = 1; i <= n; i++) {
    scanf("%d", &(aa[i]));
    ;
    pos[aa[i]] = i;
  }
  int x, y, c;
  for (int i = 1; i <= n; i++) {
    scanf("%d", &(bb[i]));
    ;
    x = i;
    y = pos[bb[i]];
    mpp[x] = y;
    tot++;
    a[tot] = node(tot, 1, x, y, 0, 1);
  }
  int x11, y11;
  while (m--) {
    scanf("%d", &op);
    if (op == 2) {
      scanf("%d %d", &(x), &(y));
      tot++;
      a[tot] = node(tot, 1, x, mpp[x], 0, -1);
      tot++;
      a[tot] = node(tot, 1, y, mpp[y], 0, -1);
      swap(mpp[x], mpp[y]);
      tot++;
      a[tot] = node(tot, 1, x, mpp[x], 0, 1);
      tot++;
      a[tot] = node(tot, 1, y, mpp[y], 0, 1);
    } else if (op == 1) {
      int l1, r1, l2, r2;
      scanf("%d %d", &(l2), &(r2));
      scanf("%d %d", &(l1), &(r1));
      tot++;
      a[tot] = node(tot, 2, l1 - 1, l2 - 1, 1, ++anstot);
      tot++;
      a[tot] = node(tot, 2, l1 - 1, r2, -1, anstot);
      tot++;
      a[tot] = node(tot, 2, r1, l2 - 1, -1, anstot);
      tot++;
      a[tot] = node(tot, 2, r1, r2, 1, anstot);
    }
  }
  cdq(1, tot);
  for (int i = 1; i <= anstot; i++) {
    printf("%lld\n", ans[i]);
  }
  return 0;
}
inline void getInt(int *p) {
  char ch;
  do {
    ch = getchar();
  } while (ch == ' ' || ch == '\n');
  if (ch == '-') {
    *p = -(getchar() - '0');
    while ((ch = getchar()) >= '0' && ch <= '9') {
      *p = *p * 10 - ch + '0';
    }
  } else {
    *p = ch - '0';
    while ((ch = getchar()) >= '0' && ch <= '9') {
      *p = *p * 10 + ch - '0';
    }
  }
}

```