Problem: You are given an undirected connected graph with weighted edges. The length of some path between two vertices is the bitwise xor of weights of all edges belonging to this path (if some edge is traversed more than once, then it is included in bitwise xor the same number of times). 

There are three types of queries you have to process:

  * 1 x y d — add an edge connecting vertex x to vertex y with weight d. It is guaranteed that there is no edge connecting x to y before this query; 
  * 2 x y — remove an edge connecting vertex x to vertex y. It is guaranteed that there was such edge in the graph, and the graph stays connected after this query; 
  * 3 x y — calculate the length of the shortest path (possibly non-simple) from vertex x to vertex y. 



Print the answers for all queries of type 3.

Input

The first line contains two numbers n and m (1 ≤ n, m ≤ 200000) — the number of vertices and the number of edges in the graph, respectively.

Then m lines follow denoting the edges of the graph. Each line contains three integers x, y and d (1 ≤ x < y ≤ n, 0 ≤ d ≤ 230 - 1). Each pair (x, y) is listed at most once. The initial graph is connected.

Then one line follows, containing an integer q (1 ≤ q ≤ 200000) — the number of queries you have to process.

Then q lines follow, denoting queries in the following form:

  * 1 x y d (1 ≤ x < y ≤ n, 0 ≤ d ≤ 230 - 1) — add an edge connecting vertex x to vertex y with weight d. It is guaranteed that there is no edge connecting x to y before this query; 
  * 2 x y (1 ≤ x < y ≤ n) — remove an edge connecting vertex x to vertex y. It is guaranteed that there was such edge in the graph, and the graph stays connected after this query; 
  * 3 x y (1 ≤ x < y ≤ n) — calculate the length of the shortest path (possibly non-simple) from vertex x to vertex y. 



It is guaranteed that at least one query has type 3.

Output

Print the answers for all queries of type 3 in the order they appear in input.

Example

Input

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


Output

1
1
2

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
struct point {
  int x, y;
  point() {}
  point(int xx, int yy) { x = xx, y = yy; }
  bool operator<(const point &other) const {
    if (x == other.x) return y < other.y;
    return x < other.x;
  }
} temp, Q[400011 * 4];
struct Point {
  int x, y, z;
  Point() {}
  Point(int xx, int yy, int zz) { x = xx, y = yy, z = zz; }
};
struct node {
  int l, r;
} tree[400011 * 4];
point Stack1[400011];
int top1;
int Stack2[400011];
int top2;
map<point, point> Map;
map<point, point>::iterator it;
vector<Point> V[400011 * 4];
int father[400011], pre[400011], h[400011], n, m, f[31 + 1], q;
int find(int u) {
  if (u == father[u]) return u;
  return find(father[u]);
}
int ask(int u) {
  if (u == father[u]) return 0;
  return ask(father[u]) ^ pre[u];
}
void build(int l, int r, int now) {
  tree[now].l = l;
  tree[now].r = r;
  if (l == r) return;
  int mid = (l + r) / 2;
  build(l, mid, now * 2);
  build(mid + 1, r, now * 2 + 1);
}
void Insert(int l, int r, Point x, int now) {
  if (l <= tree[now].l && tree[now].r <= r) {
    V[now].push_back(x);
    return;
  }
  int mid = (tree[now].l + tree[now].r) / 2;
  if (l <= mid) Insert(l, r, x, now * 2);
  if (r > mid) Insert(l, r, x, now * 2 + 1);
}
void Add(int p, point x, int now) {
  if (tree[now].l == tree[now].r) {
    Q[now] = x;
    return;
  }
  int mid = (tree[now].l + tree[now].r) / 2;
  if (p <= mid)
    Add(p, x, now * 2);
  else
    Add(p, x, now * 2 + 1);
}
void Query(int now) {
  int ttop1 = top1, ttop2 = top2;
  int len = V[now].size();
  for (int i = 0; i < len; i++) {
    int x = V[now][i].x, y = V[now][i].y, z = V[now][i].z;
    int fx = find(x), fy = find(y);
    if (fx != fy) {
      if (h[fx] > h[fy]) swap(fx, fy);
      if (h[fx] == h[fy])
        h[fy]++, Stack1[++top1] = point(fx, fy);
      else
        Stack1[++top1] = point(fx, 0);
      father[fx] = fy, pre[fx] = (ask(y) ^ z ^ ask(x));
    } else {
      int Len = ask(x) ^ ask(y) ^ z;
      for (int i = 31; i >= 0; i--) {
        if ((Len >> i) & 1) {
          if (f[i])
            Len ^= f[i];
          else {
            Stack2[++top2] = i;
            f[i] = Len;
            break;
          }
        }
        if (!Len) break;
      }
    }
  }
  if (tree[now].l == tree[now].r) {
    if (Q[now].x) {
      int x = Q[now].x, y = Q[now].y;
      int Len = ask(x) ^ ask(y);
      for (int i = 31; i >= 0; i--) {
        if ((Len ^ f[i]) < Len) Len ^= f[i];
      }
      printf("%d\n", Len);
    }
    while (top1 != ttop1) {
      int x = Stack1[top1].x;
      int y = Stack1[top2].y;
      father[x] = x;
      pre[x] = 0;
      if (y) h[y]--;
      top1--;
    }
    while (top2 != ttop2) {
      int x = Stack2[top2];
      f[x] = 0;
      top2--;
    }
    return;
  }
  Query(now * 2);
  Query(now * 2 + 1);
  while (top1 != ttop1) {
    int x = Stack1[top1].x;
    int y = Stack1[top2].y;
    father[x] = x;
    pre[x] = 0;
    if (y) h[y]--;
    top1--;
  }
  while (top2 != ttop2) {
    int x = Stack2[top2];
    f[x] = 0;
    top2--;
  }
  return;
}
void init() {
  for (int i = 1; i <= n; i++) father[i] = i;
}
int main() {
  int op, x, y, z;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d%d", &x, &y, &z);
    if (x > y) swap(x, y);
    Map[point(x, y)] = point(1, z);
  }
  scanf("%d", &q);
  build(1, q, 1);
  for (int i = 1; i <= q; i++) {
    scanf("%d%d%d", &op, &x, &y);
    if (x > y) swap(x, y);
    if (op == 1) {
      scanf("%d", &z);
      Map[point(x, y)] = point(i, z);
    } else if (op == 2) {
      temp = Map[point(x, y)];
      z = temp.y;
      Insert(temp.x, i, Point(x, y, z), 1);
      Map.erase(point(x, y));
    } else {
      Add(i, point(x, y), 1);
    }
  }
  for (it = Map.begin(); it != Map.end(); it++) {
    temp = it->second;
    z = temp.y, op = temp.x;
    temp = it->first;
    x = temp.x, y = temp.y;
    Insert(op, q, Point(x, y, z), 1);
  }
  init();
  Query(1);
  return 0;
}