#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int a[n], b[m], pos[n];
    for (int i = 0; i < n; i++) cin >> a[i], --a[i];
    for (int i = 0; i < m; i++) cin >> b[i], --b[i];
    for (int i = 0; i < n; i++) pos[a[i]] = i;
    long long sum = m, left = 0;
    for (int i = 0; i < m; i++)
      if (pos[b[i]] > left) {
        sum += 2 * (pos[b[i]] - i);
        left = pos[b[i]];
      }
    cout << sum << endl;
  }
  return 0;
}
