#include <bits/stdc++.h>
using namespace std;
int a[200010], t[200010];
int work() {
  int n, x, k;
  cin >> n >> k;
  map<int, int> my_map;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    my_map[a[i]] = i;
    t[i] = -1;
  }
  long long ans = 1;
  t[0] = k;
  t[n + 1] = k;
  for (int i = 0; i < k; i++) {
    int x;
    cin >> x;
    if (my_map.find(x) == my_map.end())
      ans = 0;
    else
      t[my_map.find(x)->second] = i;
  }
  for (int i = 1; i <= n; i++) {
    int p =
        t[i] >= 0 ? (t[i - 1] < t[i] ? 1 : 0) + (t[i + 1] < t[i] ? 1 : 0) : 1;
    ans = ans * p % 998244353;
  }
  cout << ans << endl;
  return 0;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    work();
  }
  return 0;
}
