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 base {
  int num[35];
  void insert(int v) {
    for (int i = 30; i >= 0; i--)
      if (v & (1 << i)) {
        if (!num[i]) {
          num[i] = v;
          return;
        } else
          v ^= num[i];
      }
  }
  int answer(int v) {
    for (int i = 30; i >= 0; i--)
      if ((v ^ num[i]) < v) v ^= num[i];
    return v;
  }
} orz;
struct node {
  int x, y, w;
  node(int X = 0, int Y = 0, int W = 0) : x(X), y(Y), w(W) {}
} road[800010 << 1];
vector<node> rp[800010 << 2];
void insert(int u, int l, int r, int L, int R, node w) {
  if (L <= l && r <= R) {
    rp[u].push_back(w);
    return;
  }
  int mid = (l + r) >> 1;
  if (L <= mid) insert(u << 1, l, mid, L, R, w);
  if (R > mid) insert(u << 1 | 1, mid + 1, r, L, R, w);
}
int ql[800010], qr[800010], fa[800010], dep[800010], val[800010], ans[800010];
int find(int x) { return x == fa[x] ? x : find(fa[x]); }
int find_dis(int x) { return x == fa[x] ? 0 : val[x] ^ find_dis(fa[x]); }
struct node2 {
  int x, y;
  bool o;
} sta[800010];
int topp;
void work(int u, int l, int r, base p, int ltop) {
  for (int i = 0; i < rp[u].size(); i++) {
    int x = rp[u][i].x, y = rp[u][i].y, w = rp[u][i].w;
    int hx = find(x), hy = find(y);
    w ^= find_dis(x) ^ find_dis(y);
    if (hx == hy)
      p.insert(w);
    else {
      if (dep[hx] > dep[hy]) {
        swap(hx, hy);
        swap(x, y);
      }
      node2 u = (node2){hx, hy, 0};
      fa[hx] = hy;
      val[hx] = w;
      if (dep[hx] == dep[hy]) {
        dep[hy]++;
        u.o = 1;
      }
      sta[++topp] = u;
    }
  }
  if (l == r)
    ans[l] = p.answer(find_dis(ql[l]) ^ find_dis(qr[l]));
  else {
    int mid = (l + r) >> 1;
    work(u << 1, l, mid, p, topp);
    work(u << 1 | 1, mid + 1, r, p, topp);
  }
  while (topp > ltop) {
    fa[sta[topp].x] = sta[topp].x;
    val[sta[topp].x] = 0;
    dep[sta[topp].y] -= sta[topp].o;
    topp--;
  }
}
map<pair<int, int>, int> mp;
int ld[800010], rd[800010];
signed main() {
  int n, m, q;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) fa[i] = i;
  int cnt = m, tot = 1;
  for (int i = 1; i <= m; i++) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w);
    mp[make_pair(x, y)] = i;
    ld[i] = 1;
    rd[i] = -1;
    road[i] = node(x, y, w);
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int opt, x, y;
    scanf("%d%d%d", &opt, &x, &y);
    if (opt == 1) {
      int w;
      scanf("%d", &w);
      mp[make_pair(x, y)] = ++cnt;
      ld[cnt] = tot;
      rd[cnt] = -1;
      road[cnt] = node(x, y, w);
    } else if (opt == 2)
      rd[mp[make_pair(x, y)]] = tot - 1;
    else if (opt == 3) {
      ql[tot] = x;
      qr[tot] = y;
      tot++;
    }
  }
  tot--;
  for (int i = 1; i <= cnt; i++) {
    if (rd[i] == -1) rd[i] = tot;
    if (ld[i] <= rd[i]) insert(1, 1, tot, ld[i], rd[i], road[i]);
  }
  work(1, 1, tot, orz, 0);
  for (int i = 1; i <= tot; i++) printf("%d\n", ans[i]);
  return 0;
}