#include <bits/stdc++.h>
using namespace std;
void rwFile() {
  freopen("INP.inp", "r", stdin);
  freopen("OUT.out", "w", stdout);
}
void solveA() {
  int t;
  cin >> t;
  while (t--) {
    long long r, g, b;
    cin >> r >> g >> b;
    long long maxx = max(r, max(g, b));
    long long tot = r + g + b;
    if (tot >= 2 * maxx - 1)
      cout << "Yes\n";
    else
      cout << "No\n";
  }
}
void solveB() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    long long s;
    cin >> n >> s;
    int res = 0;
    long long maxx = 0, pos = 0;
    long long arr[n];
    int done = 0;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
      if (done == 1) continue;
      if (arr[i] > maxx) {
        maxx = arr[i];
        pos = i + 1;
      }
      if (s < arr[i]) {
        done = 1;
        res = pos;
      }
      s -= arr[i];
    }
    cout << res << '\n';
  }
}
void solveC() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int A[n], B[m], pos[n + 1];
    for (int i = 0; i < n; i++) {
      cin >> A[i];
      pos[A[i]] = i;
    }
    for (int i = 0; i < m; i++) cin >> B[i];
    int C[n + 1];
    memset(C, 0, sizeof(C));
    int P = pos[B[0]], Count = 1;
    long long res = 2 * pos[B[0]] + 1;
    for (int i = 1; i < m; i++) {
      if (pos[B[i]] < P) {
        res++;
        Count++;
      } else {
        res += (pos[B[i]] - Count) * 2 + 1;
        Count++;
        P = pos[B[i]];
      }
    }
    cout << res << '\n';
  }
}
int main() { solveC(); }
