#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5, md = 998244353;
int n, fac[N], iv[N], pow3[N];
inline int pow(int a, int b) {
  int res = 1;
  for (; b; b >>= 1, a = (long long)a * a % md)
    if (b & 1) res = (long long)res * a % md;
  return res;
}
void init() {
  for (int i = *fac = *pow3 = 1; i <= n; ++i)
    fac[i] = (long long)fac[i - 1] * i % md, pow3[i] = pow3[i - 1] * 3LL % md;
  iv[n] = pow(fac[n], md - 2);
  for (int i = n - 1; ~i; --i) iv[i] = (i + 1uLL) * iv[i + 1] % md;
}
void solve() {
  int pn = pow3[n], fpn = pow(3, md - 1 - n);
  int s = 0, t = 0;
  for (int i = 1; i <= n; ++i) {
    int cni = (long long)fac[n] * iv[i] % md * iv[n - i] % md;
    s = (s + (long long)cni * pow3[i] % md * pow(pn, n - i) % md *
                 ((i & 1) ? md - 1 : 1)) %
        md;
    t = (t + (long long)cni * pow(md - fpn, i) % md *
                 (pow((int)(md - (long long)pow3[i] * fpn % md + 1) % md, n) +
                  md - 1)) %
        md;
  }
  int _ = pow(pow3[n], n);
  s = s * 2 % md, t = (long long)t * _ % md * 3 % md;
  int ans = (2LL * md - s - t) % md;
  cout << ans << '\n';
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  init();
  solve();
  return 0;
}
