#define _USE_MATH_DEFINES #define _CRT_SECURE_NO_DEPRECATE #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair Pii; typedef pair Pll; #define FOR(i,n) for(int i = 0; i < (n); i++) #define sz(c) ((int)(c).size()) #define ten(x) ((int)1e##x) #define tenll(x) ((ll)1e##x) template T gcd(T a, T b) { return b ? gcd(b, a % b) : a; } const int MOD = ten(9) + 7; typedef vector Row; typedef vector Mat; Mat mul(const Mat& a, const Mat& b) { int n = a.size(); int m = a[0].size(); int x = b.size(); int y = b[0].size(); assert(m == x); Mat c(n, Row(y)); for (int i = 0; i < n; ++i) for (int k = 0; k < m; ++k) for (int j = 0; j < y; ++j) (c[i][j] += a[i][k] * b[k][j]) %= MOD; return c; } Mat pow(const Mat& _a, ll e) { Mat a = _a; int n = a.size(); Mat res(n, Row(n)); for (int i = 0; i < n; ++i) res[i][i] = 1; while (e > 0) { if (e & 1) res = mul(res, a); a = mul(a, a); e /= 2; } return res; } template ll mod_pow(T a, T n, T mod){ ll ret = 1; ll p = a % mod; while (n) { if (n & 1) ret = ret * p % mod; p = p * p % mod; n >>= 1; } return ret; } ll fib(ll n){ // 0,1,1,2,3,5,8 ...; if (n == 0) return 0; Mat b = Mat(2,Row(2)); b[0][0] = b[0][1] = b[1][0] = 1; return pow(b, n - 1)[0][0]; } int main(){ int n; cin >> n; ll ans = 1; while (n--) { ll c; char s[1000]; scanf("%lld%s", &c, &s); ll d = 0; for (int i = 0; s[i]; i++) { d = d * 10 + s[i] - '0'; if (d > MOD - 1) d %= MOD - 1; } ll cur = fib(c + 2); ans = ans * mod_pow(cur, d, MOD) % MOD; } cout << ans % MOD << endl; }