#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
long long n, ans;
long long c[1000010];
const long long mod = 998244353;
long long ksm(long long a, long long b) {
  long long ans = 1, base = a;
  while (b != 0) {
    if (b & 1) {
      ans = ans * base % mod;
    }
    base = base * base % mod;
    b >>= 1;
  }
  return ans;
}
void init() {
  c[0] = 1;
  for (long long i = 1; i <= n; i++) {
    c[i] = c[i - 1] * (n - i + 1) % mod * ksm(i, mod - 2) % mod;
  }
}
int main() {
  cin >> n;
  init();
  {
    long long now = -1;
    for (int i = 1; i <= n; i++) {
      now = -now;
      ans =
          (ans + 2ll * now * c[i] * ksm(3, n * (n - i) + i) % mod + mod) % mod;
    }
  }
  {
    long long now = 1, three = ksm(3, n * n + 1);
    long long inv1, inv2;
    for (int i = 1; i <= n; i++) {
      now = -now;
      inv1 = ksm(ksm(3, n * i), mod - 2);
      inv2 = ksm(1 - ksm(ksm(3, n - i), mod - 2), n) - 1;
      ans = (ans - three * c[i] % mod * inv1 % mod * now * inv2 % mod + mod) %
            mod;
    }
    cout << ans << endl;
  }
  return 0;
}
