#include <bits/stdc++.h>
using namespace std;
const int base = 998244353;
long long pw[1000010], npw[1000010];
long long lt(long long a, long long n) {
  long long res = 1;
  for (; n; a = (a * a) % base, n >>= 1ll)
    if (n & 1ll) res = (res * a) % base;
  return res;
}
long long c(int k, int n) {
  if (k > n) return 0;
  return ((pw[n] * npw[n - k] % base) * npw[k]) % base;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n;
  cin >> n;
  long long res = 0, ans = 0;
  pw[0] = 1;
  for (int i = 1; i <= n; ++i) pw[i] = (pw[i - 1] * i) % base;
  npw[n] = lt(pw[n], base - 2);
  for (int i = n - 1; i >= 0; --i) npw[i] = (npw[i + 1] * (i + 1)) % base;
  for (int i = 1; i <= n; ++i)
    res = (res +
           ((c(i, n) * lt(3, n * n - n * i + i)) % base * lt(base - 1, i + 1)) %
               base) %
          base;
  for (int i = 0; i < n; ++i) {
    long long x = c(i, n) * lt(base - 1, i + 1) % base;
    long long y = (lt((1 + base - lt(3, i)) % base, n) -
                   lt((base - lt(3, i)) % base, n)) %
                  base;
    y = (y + base) % base;
    ans = (ans + x * y) % base;
  }
  res = (res * 2 + ans * 3) % base;
  cout << (res % base + base) % base;
}
