#include <bits/stdc++.h>
using namespace std;
signed main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    long long n, m;
    cin >> n >> m;
    vector<long long> pos(n);
    for (long long i = 0; i < n; i++) {
      long long x;
      cin >> x;
      pos[x - 1] = i;
    }
    long long max_pos = 0;
    long long res = 0;
    for (long long i = 0; i < m; i++) {
      long long x;
      cin >> x;
      if (pos[x - 1] >= max_pos) {
        res += ((pos[x - 1] - i) << 1) | 1;
        max_pos = pos[x - 1];
      } else
        res += 1;
    }
    cout << res << endl;
  }
}
