#include <iostream>
#include <bitset>
#include <vector>
#include <algorithm>
int n, m, q;
int sT, sB;
std::vector<int> E[100007];
int a[100007], b[100007];
bool vis[100007];
std::bitset<100007> to[100007];
void dfs(int u) {
to[u].reset();
vis[u] = true;
to[u][u] = true;
for (int v : E[u]) {
if (!vis[v]) {
dfs(v);
}
to[u] |= to[v];
}
}
int Query[100007][4];
int aa[100007], bb[100007];
int aa_1[100007];
bool imp[100007];
int bl[100007], br[100007], B[100007];
int ans[107][100007];
int impvec[4007][4007], top[4007];
std::pair<int, int> rE[200007];
inline int query(int u, int l, int r) {
if (B[l] == B[r]) {
int res = 0;
for (int i = l; i <= r; ++i) {
if (to[u][aa_1[i]]) {
res = std::max(res, bb[aa_1[i]]);
}
}
return res;
}
int res = 0;
for (int i = l; i <= br[B[l]]; ++i) {
if (to[u][aa_1[i]]) {
res = std::max(res, bb[aa_1[i]]);
}
}
for (int i = bl[B[r]]; i <= r; ++i) {
if (to[u][aa_1[i]]) {
res = std::max(res, bb[aa_1[i]]);
}
}
for (int i = B[l] + 1; i < B[r]; ++i) {
res = std::max(res, ans[i][u]);
for (int j_ = 1; j_ <= top[i]; ++j_) {
int j = impvec[i][j_];
if (to[u][aa_1[j]]) {
res = std::max(res, bb[aa_1[j]]);
}
}
}
return res;
}
inline void solveTimeBlock(int Q) {
for (int i = 1; i <= n; ++i) {
aa[i] = a[i], bb[i] = b[i];
aa_1[aa[i]] = i;
imp[i] = 0;
}
for (int i = 1; i <= Q; ++i) {
int o, x, y, z;
std::cin >> o >> x >> y;
if (o == 3) {
std::cin >> z;
Query[i][0] = o, Query[i][1] = x, Query[i][2] = y, Query[i][3] = z;
} else {
Query[i][0] = o, Query[i][1] = x, Query[i][2] = y;
if (o == 1) {
int plcx = aa[x], plcy = aa[y];
imp[plcx] = imp[plcy] = true;
std::swap(aa[x], aa[y]);
std::swap(aa_1[plcx], aa_1[plcy]);
} else {
int plcx = aa[x], plcy = aa[y];
imp[plcx] = imp[plcy] = true;
std::swap(bb[x], bb[y]);
}
}
}
for (int i = 1; i <= B[n]; ++i) {
for (int j = 1; j <= n; ++j) {
ans[i][j] = 0;
}
for (int j = bl[i]; j <= br[i]; ++j) {
if (!imp[j]) {
ans[i][aa_1[j]] = b[aa_1[j]];
}
}
for (int j = 1; j <= m; ++j) {
ans[i][rE[j].second] = std::max(ans[i][rE[j].second], ans[i][rE[j].first]);
}
top[i] = 0;
}
for (int i = 1; i <= n; ++i) {
aa[i] = a[i], bb[i] = b[i];
aa_1[aa[i]] = i;
if (imp[i]) {
impvec[B[i]][++top[B[i]]] = i;
}
}
for (int i = 1; i <= Q; ++i) {
int o, x, y, z;
o = Query[i][0], x = Query[i][1], y = Query[i][2];
if (o == 3) {
z = Query[i][3];
std::cout << query(x, y, z) << '\n';
} else {
if (o == 1) {
int plcx = aa[x], plcy = aa[y];
std::swap(aa[x], aa[y]);
std::swap(aa_1[plcx], aa_1[plcy]);
} else {
int plcx = aa[x], plcy = aa[y];
std::swap(bb[x], bb[y]);
}
}
}
for (int i = 1; i <= n; ++i) {
a[i] = aa[i], b[i] = bb[i];
}
}
void solve() {
std::cin >> n >> m >> q;
for (int i = 1; i <= n; ++i) {
std::vector<int>().swap(E[i]);
vis[i] = false;
}
for (int i = 1; i <= m; ++i) {
int u, v;
std::cin >> u >> v;
E[u].push_back(v);
rE[i] = {v, u};
}
std::sort(rE + 1, rE + m + 1, std::greater<>());
for (int i = 1; i <= n; ++i) {
std::cin >> a[i];
}
for (int i = 1; i <= n; ++i) {
std::cin >> b[i];
bl[i] = br[i] = 0;
}
for (int i = 1; i <= n; ++i) {
if (!vis[i]) {
dfs(i);
}
}
sT = 3000, sB = 3400;
for (int i = 1; i <= n; ++i) {
B[i] = (i - 1) / sB + 1, br[B[i]] = i;
if (bl[B[i]] == 0) {
bl[B[i]] = i;
}
}
int nodecnt = 0;
for (int i = 1; i <= (q + sT - 1) / sT; ++i) {
int l = (i - 1) * sT + 1, r = std::min(i * sT, q);
solveTimeBlock(r - l + 1);
}
}
int main() {
std::freopen("recall.in", "r", stdin);
std::freopen("recall.out", "w", stdout);
std::cin.tie(nullptr)->sync_with_stdio(false);
int t;
std::cin >> t >> t;
while (t--) {
solve();
}
return 0;
}