#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
const int MN = 1000010;
int exp(int x, long long n) {
  int ret = 1;
  while (n) {
    if (n & 1) ret = 1LL * ret * x % mod;
    x = 1LL * x * x % mod;
    n >>= 1;
  }
  return ret;
}
int inv(int x) { return exp(x, mod - 2); }
int fact[MN], invf[MN];
int comb(int n, int k) {
  return 1LL * fact[n] * invf[k] % mod * invf[n - k] % mod;
}
int N;
int main() {
  fact[0] = 1;
  for (int i = 1; i < MN; i++) {
    fact[i] = 1LL * fact[i - 1] * i % mod;
  }
  for (int i = 0; i < MN; i++) {
    invf[i] = inv(fact[i]);
  }
  cin >> N;
  int ans = 0;
  for (int i = 1; i <= N; i++) {
    if (i % 2) {
      ans += 2LL * comb(N, i) * exp(3, 1LL * N * (N - i) + i) % mod;
      ans %= mod;
    } else {
      ans += mod - 2LL * comb(N, i) * exp(3, 1LL * N * (N - i) + i) % mod;
      ans %= mod;
    }
  }
  for (int i = 1; i <= N; i++) {
    if (i % 2) {
      ans += 1LL * exp(3, 1LL * N * (N - i) + 1) * comb(N, i) % mod *
             (exp(mod + 1 - exp(inv(3), N - i), N) + mod - 1) % mod;
      ans %= mod;
    } else {
      ans += mod - 1LL * exp(3, 1LL * N * (N - i) + 1) * comb(N, i) % mod *
                       (exp(mod + 1 - exp(inv(3), N - i), N) + mod - 1) % mod;
      ans %= mod;
    }
  }
  cout << ans;
}
