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>
const int ms = 1 << 18;
const int me = 31;
struct Edge {
  int x, y, w;
};
struct Info {
  int x, y, idx;
};
struct Disjoint_Set {
 public:
  struct Element {
    Element(int i = 0) {
      par = i;
      for (int j = 0; j < me; j++) {
        gauss[j] = 0;
      }
      up = 0;
      size = 1;
    }
    int par;
    int gauss[me];
    int up;
    int size;
    void add(int x) {
      for (int j = me - 1; j >= 0; j--) {
        if (x & (1 << j)) {
          if (gauss[j] == 0) {
            gauss[j] = x;
            break;
          }
          x ^= gauss[j];
        }
      }
    }
    int qry(int x) {
      for (int j = me - 1; j >= 0; j--) {
        x = std::min(x, x ^ gauss[j]);
      }
      return x;
    }
    void make_union(Element e) {
      for (int j = 0; j < me; j++) {
        if (e.gauss[j] != 0 || e.size >= me) {
          add(e.gauss[j]);
        }
      }
      size += e.size;
    }
  };
  void init(int n) {
    nodes.resize(n);
    for (int i = 0; i < n; i++) {
      nodes[i] = Element(i);
    }
  }
  int make_union(int a, int b, int w) {
    std::pair<int, int> elems[2];
    elems[0] = get_par(a);
    elems[1] = get_par(b);
    a = elems[0].first;
    b = elems[1].first;
    if (a == b) {
      st.push_back(nodes[a]);
      nodes[a].add(elems[0].second ^ elems[1].second ^ w);
      return 1;
    } else {
      if (nodes[a].size < nodes[b].size) {
        std::swap(a, b);
        std::swap(elems[0], elems[1]);
      }
      st.push_back(nodes[a]);
      st.push_back(nodes[b]);
      nodes[b].up = w ^ elems[1].second ^ elems[0].second;
      nodes[b].par = a;
      nodes[a].make_union(nodes[b]);
      return 2;
    }
  }
  int qry(int u, int v) {
    int top = get_par(u).first;
    int w = get_par(u).second ^ get_par(v).second;
    return nodes[top].qry(w);
  }
  std::pair<int, int> get_par(int a, int x = 0) {
    if (a == nodes[a].par) {
      return std::pair<int, int>(a, x);
    } else {
      return get_par(nodes[a].par, x ^ nodes[a].up);
    }
  }
  void roll_back() {
    nodes[st.back().par] = st.back();
    st.pop_back();
  }

 private:
  std::vector<Element> nodes;
  std::vector<Element> st;
};
std::vector<Edge> tree[2 * ms];
std::vector<Info> queries[ms];
int k;
void add(int l, int r, Edge e) {
  for (l += ms, r += ms; l < r; l /= 2, r /= 2) {
    if (l & 1) {
      tree[l++].push_back(e);
    }
    if (r & 1) {
      tree[--r].push_back(e);
    }
  }
}
Disjoint_Set DSU;
int ans[ms];
void dfs(int p = 1) {
  int got = 0;
  for (auto e : tree[p]) {
    got += DSU.make_union(e.x, e.y, e.w);
  }
  if (p >= ms) {
    p -= ms;
    for (auto a : queries[p]) {
      ans[a.idx] = DSU.qry(a.x, a.y);
    }
  } else {
    dfs(p + p);
    dfs(p + p + 1);
  }
  while (got--) {
    DSU.roll_back();
  }
}
int main() {
  int n, m;
  std::cin >> n >> m;
  DSU.init(n);
  int q = 0;
  std::map<std::pair<int, int>, std::pair<int, int> > from;
  for (int i = 0; i < m; i++) {
    int x, y, w;
    scanf("%i %i %i", &x, &y, &w);
    x--;
    y--;
    from[std::pair<int, int>(x, y)] = std::pair<int, int>(0, w);
  }
  std::cin >> m;
  for (int i = 1; i <= m; i++) {
    int t, x, y;
    scanf("%i %i %i", &t, &x, &y);
    x--;
    y--;
    if (t == 1) {
      int w;
      scanf("%i", &w);
      from[std::pair<int, int>(x, y)] = std::pair<int, int>(i, w);
    } else if (t == 2) {
      std::pair<int, int> wut = from[std::pair<int, int>(x, y)];
      int l = wut.first;
      int r = i;
      int w = wut.second;
      Edge e;
      e.x = x;
      e.y = y;
      e.w = w;
      add(l, r, e);
      from.erase(std::pair<int, int>(x, y));
    } else {
      Info a;
      a.x = x;
      a.y = y;
      a.idx = q++;
      queries[i].push_back(a);
    }
  }
  for (auto e : from) {
    Edge a;
    a.x = e.first.first;
    a.y = e.first.second;
    a.w = e.second.second;
    int l = e.second.first;
    int r = m + 1;
    add(l, r, a);
  }
  dfs();
  for (int i = 0; i < q; i++) {
    printf("%i\n", ans[i]);
  }
}