#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t, n, m, b, c, j;
  cin >> t;
  for (long long x = 0; x < t; x++) {
    cin >> n >> m;
    c = j = 0;
    long long a[n];
    vector<bool> d(n, false);
    for (long long i = 0; i < n; i++) {
      cin >> a[i];
      a[i]--;
    }
    for (long long i = 0; i < m; i++) {
      cin >> b;
      b--;
      if (d[b]) {
        c++;
      } else {
        while (a[j] != b) {
          d[a[j]] = true;
          j++;
        }
        c += 2 * (j - i) + 1;
      }
    }
    cout << c << '\n';
  }
}
