#include <bits/stdc++.h>
using namespace std;
const int mod = 998244353;
int n, ans1, ans2;
int power[1000050], inv[1000050];
int AD(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
int LE(int x, int y) { return x - y < 0 ? x - y + mod : x - y; }
int fastpower(int x, long long y, int ans = 1) {
  for (; y; y >>= 1, x = 1LL * x * x % mod)
    if (y & 1) ans = 1LL * ans * x % mod;
  return ans;
}
void first() {
  inv[0] = inv[1] = power[0] = 1;
  for (int i = 1; i <= n; ++i) power[i] = 1LL * power[i - 1] * i % mod;
  for (int i = 2; i <= n; ++i)
    inv[i] = 1LL * inv[mod % i] * (mod - mod / i) % mod;
  for (int i = 1; i <= n; ++i) inv[i] = 1LL * inv[i - 1] * inv[i] % mod;
}
int C(int x, int y) { return 1LL * power[x] * inv[y] % mod * inv[x - y] % mod; }
int main() {
  scanf("%d", &n);
  if (n == 1) printf("3"), exit(0);
  first();
  for (int i = 0; i < n; ++i) {
    if (i & 1)
      ans1 = AD(ans1, 1LL * C(n, i) *
                          LE(fastpower(LE(1, fastpower(3, i)), n),
                             fastpower(LE(0, fastpower(3, i)), n)) %
                          mod);
    else
      ans1 = LE(ans1, 1LL * C(n, i) *
                          LE(fastpower(LE(1, fastpower(3, i)), n),
                             fastpower(LE(0, fastpower(3, i)), n)) %
                          mod);
  }
  for (int i = 1; i <= n; ++i) {
    if (i & 1)
      ans2 =
          AD(ans2, 1LL * C(n, i) * fastpower(3, 1LL * n * (n - i) + i) % mod);
    else
      ans2 =
          LE(ans2, 1LL * C(n, i) * fastpower(3, 1LL * n * (n - i) + i) % mod);
  }
  printf("%d", AD(2LL * ans2 % mod, 3LL * ans1 % mod));
  return 0;
}
