#include <bits/stdc++.h>
using namespace std;
const int M = 998244353, Maxn = 1e6 + 10;
int n, pw1[Maxn], pw2[Maxn], fac[Maxn], ifac[Maxn], inv[Maxn];
int mo1(int x) { return (x >= M) ? x - M : x; }
int mo2(int x) { return (x < 0) ? x + M : x; }
int mo(long long x) { return mo2(x % M); }
int fpow(int a, int p = M - 2) {
  int ret = 1;
  for (; p; p >>= 1, a = 1ll * a * a % M)
    if (p & 1) ret = 1ll * ret * a % M;
  return ret;
}
void init(int n) {
  pw1[0] = 1;
  for (int i = 1; i <= n; i++) pw1[i] = 1ll * pw1[i - 1] * 3 % M;
  pw2[0] = 1, pw2[1] = pw1[n];
  for (int i = 2; i <= n; i++) pw2[i] = 1ll * pw2[i - 1] * pw2[1] % M;
  inv[1] = 1;
  for (int i = 2; i <= n; i++) inv[i] = M - 1ll * inv[M % i] * (M / i) % M;
  fac[0] = ifac[0] = 1;
  for (int i = 1; i <= n; i++) {
    fac[i] = 1ll * fac[i - 1] * i % M;
    ifac[i] = 1ll * ifac[i - 1] * inv[i] % M;
  }
}
int C(int n, int m) {
  return (n < m) ? 0 : 1ll * fac[n] * ifac[m] % M * ifac[n - m] % M;
}
int main() {
  int n;
  scanf("%d", &n);
  init(n);
  int T = 0;
  for (int i = 1; i <= n; i++)
    T = mo(T + ((i & 1) ? -1ll : 1ll) * C(n, i) * pw2[n - i] % M *
                   (fpow(1 - fpow(pw1[n - i]), n) - 1));
  T = 1ll * T * 3 % M;
  int ans = 0;
  for (int i = 1; i <= n; i++)
    ans = mo(ans + ((i & 1) ? -1ll : 1ll) * C(n, i) * pw1[i] % M * pw2[n - i]);
  ans = mo1(ans << 1);
  ans = (0ll + pw2[n] + ans + T) % M;
  printf("%d\n", mo2(pw2[n] - ans));
  return 0;
}
