#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int i, t, n, m, mmax, k, j, kolvo;
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> n >> m;
    vector<long long int> a(n), b(m), pl(n + 1);
    mmax = -1;
    for (j = 0; j < n; j++) {
      cin >> a[j];
      pl[a[j] - 1] = j;
    }
    k = 0;
    kolvo = 0;
    for (j = 0; j < m; j++) {
      cin >> b[j];
      if (j == 0 || pl[b[j] - 1] > mmax) {
        k += 2 * (pl[b[j] - 1] - kolvo) + 1;
        mmax = pl[b[j] - 1];
      } else
        k++;
      kolvo++;
    }
    cout << k << '\n';
  }
  return 0;
}
