#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 100;
int a[maxn], b[maxn], p[maxn];
int n, m;
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= m; i++) cin >> b[i];
    for (int i = 1; i <= n; i++) p[a[i]] = i;
    int maxp = -1;
    long long ans = 0;
    for (int i = 1; i <= m; i++) {
      int nowp = p[b[i]];
      if (nowp > maxp) {
        maxp = nowp;
        ans += (nowp - 1 - (i - 1)) * 2 + 1;
      } else
        ans += 1;
    }
    cout << ans << endl;
  }
  return 0;
}
