#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 4, P = 998244353;
inline long long Get() {
  register char c = getchar();
  register long long t = 0, f = 0;
  while (c < '0' || c > '9') {
    if (c == '-') f = 1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') t = (t << 3) + (t << 1) + c - '0', c = getchar();
  return f ? -t : t;
}
long long inv[N], fac[N];
long long n, K;
inline long long Pow(long long a, long long b) {
  long long mul = 1ll;
  while (b) {
    if (b & 1) (mul *= a) %= P;
    (a *= a) %= P;
    b >>= 1;
  }
  return mul;
}
inline long long C(long long a, long long b) {
  return fac[a] * inv[a - b] % P * inv[b] % P;
}
int main() {
  n = Get();
  K = 3;
  fac[0] = 1ll;
  for (long long i = 1; i <= n; ++i) fac[i] = (fac[i - 1] * i) % P;
  inv[n] = Pow(fac[n], P - 2);
  for (int i = (n - 1); i >= (1); --i) inv[i] = inv[i + 1] * (i + 1) % P;
  inv[0] = 1ll;
  long long ans = 0ll;
  int sgn = -1;
  for (long long i = 1; i <= n; ++i) {
    sgn = -sgn;
    (ans += C(n, i) * Pow(K, n * (n - i) + i) % P * sgn + P) %= P;
  }
  (ans <<= 1) %= P;
  long long ans1 = 0ll;
  sgn = 1;
  for (long long i = 0; i < n; ++i) {
    sgn = -sgn;
    long long tmp = Pow(K, i);
    (ans1 +=
     C(n, i) *
         ((Pow((P - tmp + 1) % P, n) % P - Pow((P - tmp) % P, n) + P) % P) % P *
         sgn +
     P) %= P;
  }
  printf("%I64d\n", (ans + K * ans1 + P) % P);
  return 0;
}
