#include <bits/stdc++.h>
using namespace std;
using namespace std;
namespace mymaths {
const int MAX_E = 1000000;
static inline int gcd(int a, int b) {
  int r;
  while (b > 0) {
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}
static inline int lgput(int b, long long e, int mod) {
  int ac = 1;
  while (e > 0) {
    if (e & 1) ac = (long long)ac * b % mod;
    b = (long long)b * b % mod;
    e /= 2;
  }
  return ac;
}
static inline int lgput(int b, int e) {
  int ac = 1;
  while (e > 0) {
    if (e & 1) ac = ac * b;
    e /= 2;
    b = b * b;
  }
  return ac;
}
static inline int invers(int x, int mod) { return lgput(x, mod - 2, mod); }
int fact[1 + MAX_E], invfact[1 + MAX_E];
bool factinit;
static inline void initfact(int x, int mod) {
  if (!factinit) {
    fact[0] = 1;
    for (int i = 1; i <= x; ++i) fact[i] = (long long)fact[i - 1] * i % mod;
    invfact[x] = invers(fact[x], mod);
    for (int i = x - 1; i >= 0; --i)
      invfact[i] = (long long)invfact[i + 1] * (i + 1) % mod;
    factinit = true;
  }
}
static inline int comb(int n, int k, int mod) {
  int aux;
  initfact(MAX_E, mod);
  aux = (long long)fact[n] * invfact[k] % mod;
  return (long long)aux * invfact[n - k] % mod;
}
static inline int cutii(int n, int k, int mod) {
  return comb(n + k - 1, n, mod);
}
}  // namespace mymaths
const int MOD = 998244353;
int main() {
  FILE *fin = stdin;
  FILE *fout = stdout;
  int n, rez = 0;
  fscanf(fin, "%d", &n);
  for (int i = 1; i <= n; ++i) {
    int term = (long long)mymaths::comb(n, i, MOD) *
               mymaths::lgput(3, (long long)n * (n - i) + i, MOD) % MOD *
               mymaths::lgput(MOD - 1, i + 1, MOD) % MOD;
    term = 2 * term % MOD;
    rez = (rez + term) % MOD;
  }
  int term2 = 0;
  for (int i = 0; i < n; ++i) {
    int aux = (long long)mymaths::comb(n, i, MOD) *
              mymaths::lgput(MOD - 1, i + 1, MOD) % MOD;
    int aux2 = (MOD - mymaths::lgput(3, i, MOD));
    aux2 = (mymaths::lgput((aux2 + 1), n, MOD) - mymaths::lgput(aux2, n, MOD) +
            MOD) %
           MOD;
    aux = (long long)aux * aux2 % MOD;
    aux = (long long)3 * aux % MOD;
    term2 = (term2 + aux) % MOD;
  }
  fprintf(fout, "%d", (rez + term2) % MOD);
  return 0;
}
