#include <bits/stdc++.h>
using namespace std;
long long int insig;
void Out(vector<long long int> x) {
  for (long long int i = 0; i < x.size(); i++) {
    cout << x[i] << " ";
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int T;
  cin >> T;
  for (long long int t = 0; t < T; t++) {
    long long int N, M;
    cin >> N >> M;
    vector<long long int> a;
    vector<long long int> b;
    long long int cur;
    for (long long int i = 0; i < N; i++) {
      a.push_back(0);
    }
    for (long long int i = 0; i < N; i++) {
      cin >> cur;
      cur--;
      a[cur] = i;
    }
    for (long long int IBRO = 0; IBRO < M; IBRO++) {
      cin >> insig;
      b.push_back(insig);
    };
    for (long long int i = 0; i < M; i++) {
      b[i] = a[b[i] - 1];
    }
    long long int ans = 0;
    long long int ms = 0;
    for (long long int i = 0; i < M; i++) {
      if (b[i] <= ms) {
        ans++;
      } else {
        ms = b[i];
        ans++;
        ans += 2 * (b[i] - i);
      }
    }
    cout << ans << endl;
  }
  return 0;
}
