#include <bits/stdc++.h>
using namespace std;
const long long mo = 998244353;
long long jc[1000005], n, ans;
long long poww[1000005], powwn[1000005];
inline long long ksmm(long long x, long long p) {
  long long res = 1;
  while (p) {
    if (p & 1) res = (res * x) % mo;
    x = (x * x) % mo;
    p >>= 1;
  }
  return res % mo;
}
inline long long inv(long long x) { return ksmm(x, mo - 2) % mo; }
inline long long ksm(long long x, long long p) {
  if (p >= 0)
    return ksmm(x, p) % mo;
  else
    return inv(ksmm(x, -p)) % mo;
}
inline long long C(long long x, long long n) {
  return ((jc[n] * inv(jc[x])) % mo * inv(jc[n - x])) % mo;
}
signed main() {
  scanf("%lld", &n);
  n++;
  n--;
  jc[0] = 1;
  jc[1] = 1;
  for (register long long i = 2; i <= n; i++) jc[i] = (jc[i - 1] * i) % mo;
  for (register long long i = 1; i <= n; i++) poww[i] = ksm(3, i) % mo;
  powwn[0] = 1;
  for (register long long i = 1; i <= n; i++)
    powwn[i] = (powwn[i - 1] * poww[n]) % mo;
  ans = 0;
  for (register long long i = 1, sig = 1; i <= n; i++, sig = -sig) {
    ans = (ans + C(i, n) * sig * poww[i] % mo * powwn[n - i]) % mo;
  }
  ans = (ans * 2) % mo;
  ans = (ans + mo) % mo;
  long long t = 0;
  for (register long long i = 1, sig = -1; i <= n; i++, sig = -sig) {
    t = (t + (C(i, n) * ksm(3, -i * n)) % mo * sig *
                 (ksm(((1 - ksm(3, -n + i) % mo) % mo + mo) % mo, n) - 1) %
                 mo) %
        mo;
  }
  ans = ans + ((-1) * ksm(3, n * n + 1) * t) % mo;
  ans = (ans % mo + mo) % mo;
  printf("%lld", ans);
  return 0;
}
