#include <bits/stdc++.h>
using namespace std;
struct s {
  int a;
  int b;
} g[100005];
int us[100005];
int p[100005];
int main() {
  int t;
  cin >> t;
  long long ans = 0;
  for (int i = 1; i <= t; i++) {
    int n, m, flag = 0, h = 0, hh = 0;
    ans = 0;
    int maxx = 0;
    cin >> n >> m;
    for (int j = 1; j <= n; j++) {
      scanf("%d", &g[j].a);
      us[g[j].a] = j;
      g[j].b = 100000;
    }
    for (int j = 1; j <= m; j++) {
      scanf("%d", &p[j]);
      g[us[p[j]]].b = j;
    }
    long long ans = 0;
    int o;
    for (int j = 1; j <= m; j++) {
      int w = us[p[j]];
      if (flag == 0) {
        ans = ans + (w - 1) * 2 + 1;
        flag = 1;
        o = us[p[j]];
      } else {
        if (w < o) {
          ans++;
        } else {
          ans = ans + (w - j) * 2 + 1;
          o = w;
        }
      }
    }
    cout << ans << endl;
  }
}
