#include <bits/stdc++.h>
int n;
long long p = 998244353;
long long inv[1000005];
void invs() {
  inv[1] = 1;
  for (int i = 2; i <= n; i++) inv[i] = (p - p / i) * inv[p % i] % p;
}
long long awsl(long long a, long long b) {
  long long x = 1;
  if (a == -1) {
    if (b % 2 == 0) return 1;
    return -1;
  }
  while (b > 0) {
    if (b & 1 == 1) x = (x * a) % p;
    a = (a * a) % p;
    b = b / 2;
  };
  return x;
}
long long c[2000005];
void choose1() {
  c[0] = 1;
  for (int i = 1; i <= n; i++) {
    c[i] = c[i - 1] * (n - i + 1) % p;
    c[i] = c[i] * inv[i] % p;
  }
}
long long ans1 = 0;
void sum1() {
  long long s = awsl(3, n), si = awsl(3, n - 1), ssi = awsl(-1, n - 1);
  for (int i = n; i >= 1; i--) {
    ans1 = ((ans1 + c[i] * ssi * s) % p + p) % p;
    ssi = -ssi;
    s = (si * s) % p;
  }
  ans1 = (ans1 * 2) % p;
}
long long ans2 = 0;
void sum2() {
  long long si = awsl(-1, n - 1);
  long long s = 1;
  for (int i = n; i >= 1; i--) {
    ans2 =
        (ans2 + 3 * c[i] * si * (awsl(s, n) - awsl((s - 1) % p, n)) % p + p) %
        p;
    s = s * 3 % p;
    si = -si;
  }
}
int main() {
  scanf("%d", &n);
  invs();
  choose1();
  sum1();
  sum2();
  printf("%lld", (ans1 - ans2 + p) % p);
}
