#include <bits/stdc++.h>
using namespace std;
const int p = 998244353;
const int maxn = 200005;
int a[maxn], b[maxn], pos[maxn], vis[maxn];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i], pos[a[i]] = i, vis[i] = 0;
    for (int i = 1; i <= k; i++) cin >> b[i];
    reverse(b + 1, b + 1 + k);
    long long ans = 1;
    for (int i = 1; i <= k; i++) {
      long long ans1 = 2;
      if (pos[b[i]] == 1 || vis[pos[b[i]] - 1]) ans1--;
      if (pos[b[i]] == n || vis[pos[b[i]] + 1]) ans1--;
      vis[pos[b[i]]] = 1;
      ans = ans * ans1 % p;
    }
    cout << ans << endl;
  }
  return 0;
}
