#include <bits/stdc++.h>
const int md = 998244353, mxn = 1000010;
int n, ans, num[mxn], b[mxn], c[mxn], inv[mxn], p[mxn], q[mxn], r[mxn];
int power(int x, int p) {
  int num = 1;
  while (p) {
    if (p & 1) num = 1ll * num * x % md;
    x = 1ll * x * x % md;
    p >>= 1;
  }
  return num;
}
int main() {
  scanf("%d", &n);
  num[0] = inv[0] = b[0] = p[0] = r[0] = 1;
  for (int i = 1; i <= n; ++i) num[i] = 1ll * num[i - 1] * i % md;
  for (int i = 1; i <= n; ++i) b[i] = 1ll * b[i - 1] * num[i] % md;
  c[n] = power(b[n], md - 2);
  for (int i = n - 1; i; --i) c[i] = 1ll * num[i + 1] * c[i + 1] % md;
  for (int i = 1; i <= n; ++i) inv[i] = 1ll * b[i - 1] * c[i] % md;
  for (int i = 0; i <= n + 1; ++i) q[i] = (i & 1 ? md - 1 : 1);
  for (int i = 1; i <= n; ++i) p[i] = 1ll * p[i - 1] * 3 % md;
  for (int i = 1; i <= n; ++i) r[i] = 1ll * r[i - 1] * p[n] % md;
  for (int i = 1; i <= n; ++i)
    ans = (ans + 2ll * q[i + 1] *
                     ((long long)num[n] * inv[i] % md * inv[n - i] % md) % md *
                     p[i] % md * r[n - i]) %
          md;
  for (int i = 0; i < n; ++i)
    ans = (ans + 3ll * q[i + 1] % md *
                     ((long long)num[n] * inv[i] % md * inv[n - i] % md) % md *
                     (power(1 - p[i], n) - 1ll * q[n] * r[i] % md)) %
          md;
  printf("%d\n", (ans + md) % md);
  return 0;
}
