#include <bits/stdc++.h>
using namespace std;
map<long long, long long> ara;
long long arr[100005];
int main() {
  long long t, i, n, m, x;
  scanf("%lld", &t);
  while (t--) {
    long long ind, ache, prev = -1, ans = 0;
    scanf("%lld%lld", &n, &m);
    for (i = 0; i < n; i++) {
      scanf("%lld", &x);
      ara[x] = i + 1;
    }
    for (i = 0; i < m; i++) {
      scanf("%lld", &arr[i]);
      ind = ara[arr[i]];
      ache = ind - 1 - i;
      if (ind <= prev)
        ans++;
      else
        ans += (ache + ache + 1);
      prev = max(ind, prev);
    }
    printf("%lld\n", ans);
    ara.clear();
  }
  return 0;
}
