#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<int, int>;
const int MAXN = 2e5 + 10;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++) is >> *i;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
  for (auto i = begin(v); i != end(v); i++)
    os << *i << (i == end(v) - 1 ? "\n" : " ");
  return os;
}
int a[MAXN], b[MAXN], c[MAXN];
int main() {
  int t, n, m;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    int tag = 0;
    ll ans = 0;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      c[a[i]] = i;
    }
    for (int i = 1; i <= m; i++) {
      cin >> b[i];
      if (c[b[i]] > tag)
        tag = c[b[i]], ans += 2 * (c[b[i]] - i) + 1;
      else
        ans += 1;
    }
    cout << ans << '\n';
  }
  return 0;
}
