#include <bits/stdc++.h>
const int maxn = 1000007;
const int mod = 998244353;
long long fac[maxn], inv[maxn];
long long pow(long long a, int b) {
  long long r = 1;
  while (b) {
    if (b % 2 == 1) {
      r *= a;
      r = r % 998244353;
    }
    b /= 2;
    a *= a;
    a = a % 998244353;
  }
  return r;
}
long long calc(long long x, long long y) {
  return 1ll * ((fac[x] * inv[y]) % mod) * (inv[x - y]) % mod;
}
void bin_coeff(int n) {
  fac[0] = 1, inv[0] = 1;
  for (int i = 1; i <= n; i++) {
    fac[i] = 1ll * fac[i - 1] * i % mod;
    inv[i] = ::pow(fac[i], mod - 2);
  }
}
int main() {
  int n;
  std::cin >> n;
  bin_coeff(n);
  long long x = pow(3, n);
  long long ans1 = (-2 * pow(x - 3, n)) % mod + (2 * pow(x, n)) % mod;
  ans1 = ans1 % mod;
  int j = -1;
  long long z = 1;
  for (int i = 0; i < n; i++) {
    long long a = (pow(1 - z, n) - pow(-z, n)) % mod;
    long long b = j * (long long)(3 * calc(n, i) * a) % mod;
    ans1 = (ans1 + b) % mod;
    j *= -1;
    z = (z * 3) % mod;
  }
  std::cout << (ans1 + mod) % mod << std::endl;
  return 0;
}
