#include <bits/stdc++.h>
using namespace std;
const int N = 300003;
int parent[N], diameter[N];
vector<vector<int> > adjList(N);
bool vis[N];
void build(int n) {
  for (int i = 1; i <= n; i++) parent[i] = i;
}
int findParent(int x) {
  if (x == parent[x]) return x;
  return parent[x] = findParent(parent[x]);
}
void mergeSet(int x, int y) {
  int px = findParent(x), py = findParent(y);
  if (px == py) return;
  parent[px] = py;
  diameter[px] = diameter[py] =
      max((diameter[px] + 1) / 2 + (diameter[py] + 1) / 2 + 1,
          max(diameter[px], diameter[py]));
}
int dfs(int node) {
  vis[node] = true;
  int maxi = 0, secondMaxi = 0;
  for (int ch : adjList[node]) {
    if (!vis[ch]) {
      int x = dfs(ch);
      if (x + 1 >= maxi)
        secondMaxi = maxi, maxi = x + 1;
      else if (x + 1 > secondMaxi)
        secondMaxi = x + 1;
    }
  }
  int p = findParent(node);
  diameter[p] = max(diameter[p], maxi + secondMaxi);
  return maxi;
}
int main() {
  int n, m, q, x, y;
  scanf("%d %d %d", &n, &m, &q);
  build(n);
  while (m--) {
    scanf("%d %d", &x, &y);
    adjList[x].push_back(y);
    adjList[y].push_back(x);
    mergeSet(x, y);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  while (q--) {
    scanf("%d", &x);
    if (x == 1) {
      scanf("%d", &y);
      printf("%d\n", diameter[findParent(y)]);
    } else {
      scanf("%d %d", &x, &y);
      if (findParent(x) != findParent(y)) mergeSet(x, y);
    }
  }
  return 0;
}

### Prompt

Your task is to create a cpp solution to the following problem:

Andrew plays a game called "Civilization". Dima helps him.

The game has n cities and m bidirectional roads. The cities are numbered from 1 to n. Between any pair of cities there either is a single (unique) path, or there is no path at all. A path is such a sequence of distinct cities v1, v2, ..., vk, that there is a road between any contiguous cities vi and vi + 1 (1 ≤ i < k). The length of the described path equals to (k - 1). We assume that two cities lie in the same region if and only if, there is a path connecting these two cities.

During the game events of two types take place:

  1. Andrew asks Dima about the length of the longest path in the region where city x lies. 
  2. Andrew asks Dima to merge the region where city x lies with the region where city y lies. If the cities lie in the same region, then no merging is needed. Otherwise, you need to merge the regions as follows: choose a city from the first region, a city from the second region and connect them by a road so as to minimize the length of the longest path in the resulting region. If there are multiple ways to do so, you are allowed to choose any of them. 



Dima finds it hard to execute Andrew's queries, so he asks you to help him. Help Dima.

Input

The first line contains three integers n, m, q (1 ≤ n ≤ 3·105; 0 ≤ m < n; 1 ≤ q ≤ 3·105) — the number of cities, the number of the roads we already have and the number of queries, correspondingly.

Each of the following m lines contains two integers, ai and bi (ai ≠ bi; 1 ≤ ai, bi ≤ n). These numbers represent the road between cities ai and bi. There can be at most one road between two cities.

Each of the following q lines contains one of the two events in the following format:

  * 1 xi. It is the request Andrew gives to Dima to find the length of the maximum path in the region that contains city xi (1 ≤ xi ≤ n). 
  * 2 xi yi. It is the request Andrew gives to Dima to merge the region that contains city xi and the region that contains city yi (1 ≤ xi, yi ≤ n). Note, that xi can be equal to yi. 

Output

For each event of the first type print the answer on a separate line.

Examples

Input

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


Output

4

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
const int N = 300003;
int parent[N], diameter[N];
vector<vector<int> > adjList(N);
bool vis[N];
void build(int n) {
  for (int i = 1; i <= n; i++) parent[i] = i;
}
int findParent(int x) {
  if (x == parent[x]) return x;
  return parent[x] = findParent(parent[x]);
}
void mergeSet(int x, int y) {
  int px = findParent(x), py = findParent(y);
  if (px == py) return;
  parent[px] = py;
  diameter[px] = diameter[py] =
      max((diameter[px] + 1) / 2 + (diameter[py] + 1) / 2 + 1,
          max(diameter[px], diameter[py]));
}
int dfs(int node) {
  vis[node] = true;
  int maxi = 0, secondMaxi = 0;
  for (int ch : adjList[node]) {
    if (!vis[ch]) {
      int x = dfs(ch);
      if (x + 1 >= maxi)
        secondMaxi = maxi, maxi = x + 1;
      else if (x + 1 > secondMaxi)
        secondMaxi = x + 1;
    }
  }
  int p = findParent(node);
  diameter[p] = max(diameter[p], maxi + secondMaxi);
  return maxi;
}
int main() {
  int n, m, q, x, y;
  scanf("%d %d %d", &n, &m, &q);
  build(n);
  while (m--) {
    scanf("%d %d", &x, &y);
    adjList[x].push_back(y);
    adjList[y].push_back(x);
    mergeSet(x, y);
  }
  for (int i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  while (q--) {
    scanf("%d", &x);
    if (x == 1) {
      scanf("%d", &y);
      printf("%d\n", diameter[findParent(y)]);
    } else {
      scanf("%d %d", &x, &y);
      if (findParent(x) != findParent(y)) mergeSet(x, y);
    }
  }
  return 0;
}

```