for (int t = (cin >> t, t); t--; ) { int n; cin >> n;
map<pair<int, int>, int> mp; vector<pair<int, int>> a(n); for (int i = 0; i < n; i++) { cin >> a[i].first; } for (int i = 0; i < n; i++) { cin >> a[i].second; } for (int i = 0; i < n; i++) { mp[a[i]] = i; }
bool ok = true; vector<pair<int, int>> res; auto add = [&](int i, int j) { if (i == j) return; swap(a[i], a[j]); swap(mp[a[i]], mp[a[j]]); res.push_back({ i, j }); }; int maxcnt = n % 2; int id = 0; for (int i = 0; i < n; i++) { auto [x, y] = a[i]; if (x == y) { if (--maxcnt < 0) { ok = false; } else { id = i; } } } if (n % 2 == 1) { add(id, n / 2); } for (int i = 0; i < n; i++) { auto [x, y] = a[i]; if (!mp.count({ y, x })) { ok = false; } else { add(n - 1 - i, mp[{ y, x }]); } }
if (!ok) { cout << -1 << endl; } else { cout << res.size() << endl; for (auto [x, y] : res) { cout << x + 1 << " " << y + 1 << endl; } } }