import core.bitop;
import std.algorithm;
import std.array;
import std.ascii;
import std.container;
import std.conv;
import std.format;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void main()
{
  int n = readln.chomp.to!int;
  char[][] field = new char[][](4, n + 2);
  foreach (ref line; field)
  {
    line[] = '*';
  }
  int[char] cnt;
  foreach (i, c; readln.chomp)
  {
    field[1][i + 1] = c;
    cnt[c]++;
  }
  foreach (i, c; readln.chomp)
  {
    field[2][i + 1] = c;
    cnt[c]++;
  }

  bool[char] done;
  long sum = 1;
  enum MOD = 1_000_000_007L;
  bool x;
  int ofs;
  if (field[1][1] == field[2][1]) {
    sum *= 3;
    x = true;
    ofs = 2;
  } else {
    sum *= 6;
    x = false;
    ofs = 3;
  }
  for (int c = ofs; c <= n;)
  {
    long t;
    bool nx = field[1][c] == field[2][c];
    final switch (x << 1 | nx) {
      case 0:
        sum *= 3;
        break;
      case 1:
        sum *= 1;
        break;
      case 2:
        sum *= 2;
        break;
      case 3:
        sum *= 2;
        break;
    }
    if (nx) {
      ++c;
    } else {
      c += 2;
    }
    x = nx;
    sum %= MOD;
  }
  sum.writeln;
}
