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;
inline long long read() {
  long long x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
const int maxn = 4e5 + 10;
int n, m, Q, num, tim, en[maxn];
int fa[maxn], dis[maxn], top, dep[maxn];
struct node {
  int x, val;
} sta[maxn];
struct Edge {
  int from, to, val;
} e[maxn];
struct Que {
  int x, y;
} q[maxn];
map<pair<int, int>, int> mp;
vector<int> V[maxn];
int getf(int x) {
  while (x != fa[x]) x = fa[x];
  return x;
}
int getd(int x) {
  int val = 0;
  while (x != fa[x]) val ^= dis[x], x = fa[x];
  return val;
}
void merge(int x, int y, int val) {
  int fx = getf(x), fy = getf(y);
  if (dep[fx] > dep[fy]) swap(fx, fy);
  sta[++top] = (node){fx, (dep[fx] == dep[fy])};
  dis[fx] = val;
  fa[fx] = fy;
  dep[fy] += (dep[fx] == dep[fy]);
}
struct LB {
  int p[40];
  void insert(int x) {
    for (int i = 30; i >= 0; --i) {
      if (!(x & (1 << i))) continue;
      if (!p[i]) {
        p[i] = x;
        break;
      }
      x ^= p[i];
    }
  }
  int query(int x) {
    for (int i = 30; i >= 0; --i)
      if ((x ^ p[i]) < x) x ^= p[i];
    return x;
  }
} L0;
struct Seg_Tree {
  vector<int> c[maxn << 2];
  void insert(int L, int R, int l, int r, int p, int x) {
    if (L <= l && R >= r) {
      c[p].push_back(x);
      return;
    }
    int mid = (l + r) >> 1;
    if (mid >= L) insert(L, R, l, mid, p << 1, x);
    if (mid < R) insert(L, R, mid + 1, r, p << 1 | 1, x);
  }
  void solve(int l, int r, int p, LB L) {
    int Nowtop = top;
    for (int i = 0; i < c[p].size(); ++i) {
      int x = e[c[p][i]].from, y = e[c[p][i]].to, val = e[c[p][i]].val;
      val ^= getd(x) ^ getd(y);
      if (getf(x) != getf(y))
        merge(x, y, val);
      else
        L.insert(val);
    }
    if (l == r)
      printf("%d\n", L.query(getd(q[l].x) ^ getd(q[l].y)));
    else {
      int mid = (l + r) >> 1;
      solve(l, mid, p << 1, L);
      solve(mid + 1, r, p << 1 | 1, L);
    }
    while (top > Nowtop) {
      dep[fa[sta[top].x]] -= sta[top].val;
      fa[sta[top].x] = sta[top].x;
      top--;
    }
  }
} T;
int main() {
  n = read(), m = read();
  for (int i = 1; i <= m; ++i) {
    e[++num].from = read(), e[num].to = read(), e[num].val = read();
    mp[make_pair(e[num].from, e[num].to)] =
        mp[make_pair(e[num].to, e[num].from)] = num;
  }
  Q = read();
  for (int i = 1; i <= num; ++i) V[i].push_back(0);
  memset(en, -1, sizeof(en));
  while (Q--) {
    int opt = read(), x = read(), y = read(), val;
    if (opt == 1) {
      val = read();
      e[++num] = (Edge){x, y, val};
      V[num].push_back(tim);
      mp[make_pair(x, y)] = mp[make_pair(y, x)] = num;
    }
    if (opt == 2)
      V[mp[make_pair(x, y)]].push_back(tim + 1), en[mp[make_pair(x, y)]] = 0;
    if (opt == 3) q[++tim] = (Que){x, y};
  }
  for (int i = 1; i <= num; ++i) {
    if (en[i] == -1) V[i].push_back(tim + 1);
    for (int j = 1; j < V[i].size(); ++j)
      if (V[i][j - 1] + 1 <= V[i][j] - 1)
        T.insert(V[i][j - 1] + 1, V[i][j] - 1, 1, tim, 1, i);
  }
  for (int i = 1; i <= n; ++i) fa[i] = i, dep[i] = 1;
  T.solve(1, tim, 1, L0);
  return 0;
}