import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.Iterator; public class Main_yukicoder147 { public static void main(String[] args) { Scanner sc = new Scanner(System.in); Printer pr = new Printer(System.out); // final int MOD = 1_000_000_007; long[][] cnt = new long[4][63]; cnt[0][0] = 1; cnt[1][0] = 0; cnt[2][0] = 0; cnt[3][0] = 1; for (int i = 1; i < 63; i++) { cnt[0][i] = (cnt[0][i - 1] * cnt[0][i - 1] % MOD + cnt[0][i - 1] * cnt[2][i - 1] % MOD + cnt[1][i - 1] * cnt[0][i - 1] % MOD) % MOD; cnt[1][i] = (cnt[0][i - 1] * cnt[1][i - 1] % MOD + cnt[0][i - 1] * cnt[3][i - 1] % MOD + cnt[1][i - 1] * cnt[1][i - 1] % MOD) % MOD; cnt[2][i] = (cnt[2][i - 1] * cnt[0][i - 1] % MOD + cnt[2][i - 1] * cnt[2][i - 1] % MOD + cnt[3][i - 1] * cnt[0][i - 1] % MOD) % MOD; cnt[3][i] = (cnt[2][i - 1] * cnt[1][i - 1] % MOD + cnt[2][i - 1] * cnt[3][i - 1] % MOD + cnt[3][i - 1] * cnt[1][i - 1] % MOD) % MOD; } int n = sc.nextInt(); long sum = 1; for (int i = 0; i < n ; i++) { long c = sc.nextLong(); char[] d = sc.next().toCharArray(); long[] ret = null; for (int j = 0; j < 63; j++) { if ((c & 0x1L << j) != 0) { if (ret == null) { ret = new long[4]; ret[0] = cnt[0][j]; ret[1] = cnt[1][j]; ret[2] = cnt[2][j]; ret[3] = cnt[3][j]; } else { long[] tmp = new long[4]; tmp[0] = (cnt[0][j] * ret[0] % MOD + cnt[0][j] * ret[2] % MOD + cnt[1][j] * ret[0] % MOD) % MOD; tmp[1] = (cnt[0][j] * ret[1] % MOD + cnt[0][j] * ret[3] % MOD + cnt[1][j] * ret[1] % MOD) % MOD; tmp[2] = (cnt[2][j] * ret[0] % MOD + cnt[2][j] * ret[2] % MOD + cnt[3][j] * ret[0] % MOD) % MOD; tmp[3] = (cnt[2][j] * ret[1] % MOD + cnt[2][j] * ret[3] % MOD + cnt[3][j] * ret[1] % MOD) % MOD; ret = tmp; } } } long cp = (ret[0] + ret[1] + ret[2] + ret[3]) % MOD; if (cp != 0) { long mod = 0; for (char e : d) { mod = mod * 10 % (MOD - 1); mod = mod + e - '0'; } sum = (sum * modPow(cp, mod)) % MOD; } else { sum = 0; } } pr.println(sum); pr.close(); sc.close(); } private static int MOD = 1_000_000_007; private static long modPow(long a, long n) { long loop = n; long ret = 1; long x = a; while (loop > 0) { if (loop % 2 == 1) { ret = ret * x % MOD; } x = x * x % MOD; loop /= 2; } return ret; } @SuppressWarnings("unused") private static class Scanner { BufferedReader br; Iterator it; Scanner (InputStream in) { br = new BufferedReader(new InputStreamReader(in)); } String next() throws RuntimeException { try { if (it == null || !it.hasNext()) { // it = Arrays.asList(br.readLine().split(" ")).iterator(); it = Arrays.asList(br.readLine().split("\\p{javaWhitespace}+")).iterator(); } return it.next(); } catch (IOException e) { throw new IllegalStateException(); } } int nextInt() throws RuntimeException { return Integer.parseInt(next()); } long nextLong() throws RuntimeException { return Long.parseLong(next()); } float nextFloat() throws RuntimeException { return Float.parseFloat(next()); } double nextDouble() throws RuntimeException { return Double.parseDouble(next()); } void close() { try { br.close(); } catch (IOException e) { // throw new IllegalStateException(); } } } private static class Printer extends PrintWriter { Printer(PrintStream out) { super(out); } } }