#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e10 + 5;
long long MOD = 998244353;
vector<long long> fac;
vector<long long> r;
vector<long long> rfac;
vector<long long> th;
vector<long long> thn;
vector<long long> deg;
long long c(int n, int k) {
  return ((((fac[n] * rfac[k]) % MOD) * rfac[n - k]) % MOD);
}
long long f(int k) {
  if (k & 1) {
    return -1;
  }
  return 1;
}
long long count(int l, int n) {
  long long s = th[l] - 1;
  long long res = 1;
  while (n > 0) {
    if (n & 1) {
      res *= s;
      res %= MOD;
      n -= 1;
    } else {
      s *= s;
      s %= MOD;
      n /= 2;
    }
  }
  return res;
}
int main() {
  int n;
  cin >> n;
  fac.assign(n + 2, 1);
  r.assign(n + 2, 1);
  rfac.assign(n + 2, 1);
  th.resize(n + 2, 1);
  thn.resize(n + 2, 1);
  deg.resize(n + 2, 1);
  for (int i = 1; i < n + 1; ++i) {
    fac[i] = (fac[i - 1] * (long long)i) % MOD;
  }
  r[1] = 1;
  for (int i = 2; i < n + 1; ++i) {
    r[i] = (MOD - ((MOD / i) * r[MOD % i]) % MOD) % MOD;
  }
  for (int i = 1; i < n + 1; ++i) {
    rfac[i] = (rfac[i - 1] * r[i]) % MOD;
  }
  for (int i = 1; i < n + 1; ++i) {
    th[i] = (th[i - 1] * 3) % MOD;
  }
  for (int i = 1; i < n + 1; ++i) {
    thn[i] = (thn[i - 1] * th[n]) % MOD;
  }
  deg[0] = 0;
  for (int i = 1; i < n + 1; ++i) {
    deg[i] = count(i, n);
  }
  long long ans = 0;
  for (int k = 1; k <= n; ++k) {
    ans +=
        ((((MOD + f((k - 1) % 2) * c(n, k)) * th[k]) % MOD) * thn[n - k]) % MOD;
    ans %= MOD;
  }
  for (int k = 1; k <= n; ++k) {
    ans += (MOD + f((k - 1) % 2) *
                      ((((((c(n, k) * (th[k] - 3)) % MOD) * thn[n - k]) % MOD) +
                        (((c(n, k) * 3) % MOD) * deg[n - k])) %
                       MOD) %
                      MOD);
    ans %= MOD;
  }
  cout << ans;
  return 0;
}
