#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
long long mod_pow(long long a, long long n) {
  if (n == 0) return 1;
  long long half = mod_pow(a, n / 2);
  long long two_half = (half * half) % MOD;
  if (n % 2 == 0)
    return two_half;
  else
    return (two_half * a) % MOD;
}
long long inv(long long a) { return mod_pow(a, MOD - 2); }
long long single_events(long long n, long long k) {
  return 2 * (mod_pow(k, n * n) - mod_pow(mod_pow(k, n) - k, n));
}
long long conj_event(long long n, long long k, long long m) {
  return mod_pow(mod_pow(k, n - m) - 1, n) - mod_pow(k, n * (n - m));
}
long long double_events(long long n, long long k) {
  long long value = 0;
  long long coeff = 1;
  for (long long m = 1; m <= n; ++m) {
    coeff *= -(n - m + 1);
    coeff %= MOD;
    coeff *= inv(m);
    coeff %= MOD;
    value = (value + coeff * conj_event(n, k, m)) % MOD;
  }
  value *= -k;
  return (MOD + value) % MOD;
}
int main() {
  long long n;
  cin >> n;
  long long k = 3;
  long long numSolutions = single_events(n, k) + double_events(n, k);
  numSolutions = (numSolutions + 10 * MOD) % MOD;
  cout << numSolutions << endl;
}
