#include <bits/stdc++.h>
using namespace std;
int a[200010], b[200010], inva[200010], hasb[200010];
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    long long res = 1;
    for (int i = 1; i <= n; i++) {
      cin >> a[i];
      inva[a[i]] = i;
      hasb[i] = 0;
    }
    for (int i = 1; i <= k; i++) {
      cin >> b[i];
      int j = inva[b[i]];
      hasb[j] = 1;
    }
    hasb[0] = hasb[n + 1] = 1;
    for (int i = 1; i <= k; i++) {
      int j = inva[b[i]];
      long long mul = 2LL - hasb[j - 1] - hasb[j + 1];
      res = (res * mul) % 998244353LL;
      hasb[j] = 0;
    }
    cout << res << endl;
  }
  return 0;
}
