import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.regex;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


immutable long MOD = 1000000007;


auto solve(long N) {
    const ACGT = ["A", "G", "C", "T"];
    const ACGT3 = cartesianProduct(ACGT, ACGT, ACGT).map!"a[0] ~ a[1] ~ a[2]".array;

    long[][string] dp;
    foreach (s; ACGT3)
        dp[s] = new long[](N);
    
    dp["CCA"][0] = 1;
    dp["CCG"][0] = 1;
    dp["CCC"][0] = 1;
    dp["CCT"][0] = 1;

    foreach (i; 1 .. N) {
        foreach (s, nc; cartesianProduct(ACGT3, ACGT)) {
            if (matchFirst(s, `.AG`.regex) && nc == "C") continue;
            if (matchFirst(s, `A.G`.regex) && nc == "C") continue;
            if (matchFirst(s, `.GA`.regex) && nc == "C") continue;
            if (matchFirst(s, `.AC`.regex) && nc == "G") continue;
            if (matchFirst(s, `AG.`.regex) && nc == "C") continue;

            const ns = s[1 .. $] ~ nc;
            dp[ns][i] += dp[s][i - 1];
            dp[ns][i] %= MOD;
        }
    }

    return ACGT3.map!(s => dp[s][N - 1]).reduce!((a, b) => (a + b) % MOD);
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(N);
    else
        solve(N).writeln;
}
