#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<int> v(n), rank(n + 1), v1(m);
    for (int i = 0; i < n; i++) {
      cin >> v[i];
      rank[v[i]] = i + 1;
    }
    for (int i = 0; i < m; i++) cin >> v1[i];
    long long cnt = 0;
    long long pre = 0;
    for (int i = 0; i < m; i++) {
      if (rank[v1[i]] < pre) {
        cnt += 1;
      } else {
        int k = rank[v1[i]] - 1;
        k -= i;
        cnt += (2 * k + 1);
        pre = rank[v1[i]];
      }
    }
    cout << cnt << endl;
  }
}
