#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, pr[255], qr[255], nxt[255], pre[255], num_bl, dp[255][255], bn, fac[255],
    st[255], num[16], num_cir;
bool vis[255], app[2][255];
int main() {
  int i, j, s, p, q;
  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &pr[i]);
    pr[i]--;
    if (pr[i] >= 0) app[0][pr[i]] = true;
  }
  for (i = 0; i < n; i++) {
    scanf("%d", &qr[i]);
    qr[i]--;
    if (qr[i] >= 0) app[1][qr[i]] = true;
  }
  memset(nxt, -1, sizeof(nxt));
  memset(pre, -1, sizeof(pre));
  for (i = 0; i < n; i++) {
    if (pr[i] < 0 && qr[i] < 0) bn++;
    if (pr[i] >= 0 && qr[i] >= 0) {
      nxt[pr[i]] = qr[i];
      pre[qr[i]] = pr[i];
    }
  }
  for (i = 0; i < n; i++) {
    j = i;
    if (!vis[j]) {
      while (true) {
        if (j >= 0) s = j;
        if (vis[j] || j < 0) break;
        vis[j] = true;
        j = pre[j];
      }
      if (j >= 0) {
        num_cir++;
        continue;
      }
      num_bl++;
      if (j < 0 && app[1][s])
        st[num_bl - 1] |= 2;
      else if (j < 0 && app[0][s])
        st[num_bl - 1] |= 1;
      s = i;
      j = nxt[i];
      while (true) {
        if (j >= 0) s = j;
        if (vis[j] || j < 0) break;
        vis[j] = true;
        j = nxt[j];
      }
      if (j < 0 && app[0][s])
        st[num_bl - 1] |= 4;
      else if (j < 0 && app[1][s])
        st[num_bl - 1] |= 8;
    }
  }
  for (i = 0; i <= num_bl; i++) {
    if (i == 0)
      fac[i] = 1;
    else
      fac[i] = (int)((long long)fac[i - 1] * (long long)i % mod);
  }
  dp[num_cir][0] = 1;
  int nst[255], cs = 0;
  for (i = 0; i < num_bl; i++) {
    if (st[i] % 4 != 2) nst[cs++] = st[i];
  }
  for (i = 0; i < num_bl; i++) {
    if (st[i] % 4 == 2 && st[i] / 4 == 1) nst[cs++] = st[i];
  }
  for (i = 0; i < num_bl; i++) {
    if (st[i] % 4 == 2 && st[i] / 4 != 1) nst[cs++] = st[i];
  }
  for (i = 0; i < num_bl; i++) st[i] = nst[i];
  cs = 0;
  for (i = 0; i <= num_bl; i++) {
    int ts = 0;
    for (s = 0; s < 16; s++) {
      if (st[i] % 4 == 2 && s / 4 == 1) continue;
      ts += num[s];
    }
    for (j = 0; j <= num_bl + num_cir; j++) {
      if (dp[j][i] == 0) continue;
      if (i == num_bl) continue;
      if (j + 1 <= num_bl + num_cir && !(st[i] % 4 == 2 && st[i] / 4 == 1))
        dp[j + 1][i + 1] = (dp[j + 1][i + 1] + dp[j][i]) % mod;
      if (!(st[i] % 4 == 2 && st[i] / 4 == 1))
        dp[j][i + 1] += (int)((long long)dp[j][i] * (long long)ts % mod);
      else
        dp[j][i + 1] += (int)((long long)dp[j][i] * (long long)(ts - cs) % mod);
      dp[j][i + 1] %= mod;
    }
    if (st[i] % 4 == 2 && st[i] / 4 == 1) cs++;
    num[st[i]]++;
  }
  for (i = 0; i < n; i++) {
    int ret;
    if (n - i > num_bl + num_cir || n - i < num_cir)
      ret = 0;
    else
      ret = (int)((long long)dp[n - i][num_bl] * (long long)fac[bn] % mod);
    printf("%d ", ret);
  }
  printf("\n");
  return 0;
}
