#include <bits/stdc++.h>
using ll = long long;
template <class t, class u, class... w>
auto operator<<(t& o, u a) -> decltype(a.print(a), o) {
  return o << "{", a.print(), o << "}";
}
using namespace std;
void DD(...) {}
using Pii = pair<int, int>;
template <class t, class u, class... w>
void DD(t s, u a, w... k) {
  while (*s && *s != ',') cerr << *s++;
  cerr << ": " << a << *s++;
  DD(s, k...);
}
template <class t, class u, class... w>
auto operator<<(t& o, u a) -> decltype((a).begin(), (a).end(), o) {
  return o << "[",
         [&]() {
           for (auto i : a) o << i << ", ";
         }(),
         o << "]";
}
using Vi = vector<int>;
template <class t, class u, class... w>
auto operator<<(t& o, u a) -> decltype(get<1>(a), o) {
  return o << "(" << a.first << ", " << a.second << ")";
}
constexpr int MOD = 998244353;
ll modInv(ll a, ll m) {
  if (a == 1) return 1;
  return ((a - modInv(m % a, a)) * m + 1) / a;
}
ll umod(ll a, ll m) {
  a %= m;
  return (a >= 0 ? a : a + m);
}
struct Zp {
  ll first;
  Zp(ll second = 0) {
    first = (second < 0 || second >= MOD ? umod(second, MOD) : second);
  }
  Zp operator-() const { return MOD - first; }
  Zp operator+(Zp r) const { return first + r.first; }
  Zp operator-(Zp r) const { return first - r.first; }
  Zp operator*(Zp r) const { return first * r.first; }
  Zp operator/(Zp r) const { return first * r.inv().first; }
  Zp inv() const { return modInv(first, MOD); }
  Zp pow(ll e) const {
    if (!e) return 1;
    Zp t = pow(e / 2);
    return t * t * (e & 1 ? first : 1);
  }
  void print(...) { cerr << first; }
};
int main() {
  cin.sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(10);
  ll n;
  cin >> n;
  const Zp three = Zp(3), one = Zp(1), neg = Zp(-1);
  Zp ret = 0;
  Zp count = n;
  for (int i = (1); i < (n + 1); i++) {
    Zp m = three.pow(n * (n - i)) * three.pow(i);
    ret = ret + count * m * 2;
    count = count / (i + 1) * (n - i) * neg;
  }
  count = 3 * n;
  if (n % 2) count = count * neg;
  for (int a = (1); a < (n + 1); a++) {
    Zp x3 = three.pow(n - a);
    Zp m = (one - x3).pow(n) - (-x3).pow(n);
    ret = ret + count * m;
    count = count / (a + 1) * (n - a) * neg;
  }
  cout << ret.first << endl;
  return 0;
}
