On one of the planets of Solar system, in Atmosphere University, many students are fans of bingo game.

It is well known that one month on this planet consists of n^2 days, so calendars, represented as square matrix n by n are extremely popular.

Weather conditions are even more unusual. Due to the unique composition of the atmosphere, when interacting with sunlight, every day sky takes one of three colors: blue, green or red.

To play the bingo, you need to observe the sky for one month — after each day, its cell is painted with the color of the sky in that day, that is, blue, green or red.

At the end of the month, students examine the calendar. If at least one row or column contains only cells of one color, that month is called lucky.

Let's call two colorings of calendar different, if at least one cell has different colors in them. It is easy to see that there are 3^{n ⋅ n} different colorings. How much of them are lucky? Since this number can be quite large, print it modulo 998244353.

Input

The first and only line of input contains a single integer n (1 ≤ n ≤ 1000 000) — the number of rows and columns in the calendar.

Output

Print one number — number of lucky colorings of the calendar modulo 998244353

Examples

Input

1


Output

3


Input

2


Output

63


Input

3


Output

9933

Note

In the first sample any coloring is lucky, since the only column contains cells of only one color.

In the second sample, there are a lot of lucky colorings, in particular, the following colorings are lucky:

<image>

While these colorings are not lucky:

<image>
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.StringTokenizer;

public class MainE {

    private FastScanner in;
    private PrintWriter out;

    long MOD = 998244353L;

    long[] gcd_ex(long a, long b) {
        if (a == 0) {
            return new long[]{0, 1};
        }
        long[] res = gcd_ex(b % a, a);
        long t = res[0];
        res[0] = res[1] - (b / a) * res[0];
        res[1] = t;
        return res;
    }

    long reverse(long a) {
        return (gcd_ex(a, MOD)[0] + 100 * MOD) % MOD;
    }

    long powMod(long a, long b) {
        long res = 1;
        long mul = a;
        while (b > 0) {
            if ((b & 1) > 0) {
                res = (res * mul) % MOD;
            }
            mul = (mul * mul) % MOD;
            b /= 2;
        }
        return res;
    }

    public void solve() {
        long N = in.nextInt();
        long[] combs = new long[(int)(N + 1)];
        combs[0] = 1;
        for (int i = 1; i <= N; i++) {
            long t = combs[i - 1];
            t = (t * (N - i + 1)) % MOD;
            t = (t * reverse(i)) % MOD;
            combs[i] = t;
        }
        long res = 0;
        long p1 = 1;
        long p2 = 1;
        long R = powMod(reverse(3), N);
        for (int i = 1; i <= N; i++) {
            p1 = (p1 * R) % MOD;
            p2 = (p2 * 3) % MOD;
            long t = combs[i] * p1 % MOD;
            t = (t * p2) % MOD;
            if ((i & 1) > 0) {
                res += 2 * t;
            } else {
                res = (res + 2 * MOD - 2 * t) % MOD;
            }
            res %= MOD;
        }
        res = res * powMod(3, N * N) % MOD;
        long i3 = 1;
        for (int i = 0; i < N; i++){
            long mi3 = (MOD - i3) % MOD;
            i3 = (i3 * 3) % MOD;
            long t = combs[i] * ((MOD + powMod(1 + mi3, N) - powMod(mi3, N)) % MOD) % MOD;
            if ((i & 1) > 0) {
                res += 3 * t;
            } else {
                res = (res + 3 * MOD - 3 * t) % MOD;
            }
            res %= MOD;
        }
        System.out.println(res);
    }

    public void run() {
        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    class FastScanner {

        BufferedReader br;
        StringTokenizer st;

        FastScanner(InputStream is) {
            br = new BufferedReader(new InputStreamReader(is));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }

    public static void main(String[] arg) {
        new MainE().run();
    }
}