#include <bits/stdc++.h>
using namespace std;
const long long maxn = 2000005;
const long long mod = 998244353;
long long n, ans, cn[maxn], pow3[maxn], pow1m[maxn];
void exgcd(long long a, long long b, long long &x, long long &y) {
  if (!b) {
    x = 1, y = 0;
  } else {
    exgcd(b, a % b, y, x);
    y -= x * (a / b);
  }
}
long long inv(long long a) {
  long long x, y;
  exgcd(a, mod, x, y);
  return (x + mod) % mod;
}
long long quickpow(long long a, long long b) {
  a %= mod;
  (a += mod) %= mod;
  long long ans = 1;
  while (b) {
    if (b & 1) (ans *= a) %= mod;
    (a *= a) %= mod;
    b >>= 1;
  }
  return ans;
}
int main() {
  cin >> n;
  cn[0] = pow3[0] = pow1m[0] = 1;
  for (long long i = 1; i <= n; ++i) {
    cn[i] = (cn[i - 1] * (n - i + 1) % mod) * inv(i) % mod;
  }
  for (long long i = 1; i < maxn; ++i) {
    pow3[i] = pow3[i - 1] * 3 % mod;
    pow1m[i] = mod - pow1m[i - 1];
  }
  for (long long i = 0; i < n; ++i) {
    (ans += cn[i] * pow1m[i + 1] % mod *
            ((quickpow(1 - pow3[i], n) - quickpow(-pow3[i], n) + mod) % mod) %
            mod) %= mod;
  }
  (ans *= 3) %= mod;
  for (int i = 1; i <= n; ++i) {
    (ans += cn[i] * pow1m[i + 1] % mod * pow3[i] % mod *
            quickpow(pow3[n], n - i) % mod * 2 % mod) %= mod;
  }
  cout << ans << endl;
  return 0;
}
