#include using namespace std; typedef long long ll; typedef vector< int > vi; typedef vector< vi > vvi; typedef vector< ll > vl; typedef vector< vl > vvl; typedef pair< int, int > pii; typedef vector< pii > vp; typedef vector< double > vd; typedef vector< vd > vvd; typedef vector< string > vs; template< class T1, class T2 > int upmin( T1 &x, T2 v ){ if( x > v ){ x = v; return 1; } return 0; } template< class T1, class T2 > int upmax( T1 &x, T2 v ){ if( x < v ){ x = v; return 1; } return 0; } const int INF = 0x3f3f3f3f; const int MOD7 = ( int ) 1e9 + 7; int N; vl C; vs D; void init(){ cin >> N; C = vl( N ); D = vs( N ); for( int i = 0; i < N; ++i ) cin >> C[ i ] >> D[ i ]; } vvi trans; vvi s1; vi d; void preprocess(){ trans = { { 0, 1 }, { 1, 1 } }; s1 = { { 2 }, { 3 } }; d = vi( N ); for( int i = 0; i < N; ++i ){ string s = D[ i ]; int f = 0; for( int j = 0; j < s.size(); ++j ) f = ( 1LL * f * 10 + s[ j ] - '0' ) % ( MOD7 - 1 ); d[ i ] = f; } } vvi mat_mul( vvi a, vvi b ){ vvi c = vvi( a.size(), vi( b[ 0 ].size() ) ); for( int i = 0; i < a.size(); ++i ) for( int j = 0; j < a[ 0 ].size(); ++j ) for( int k = 0; k < b[ 0 ].size(); ++k ) ( c[ i ][ k ] += 1LL * a[ i ][ j ] * b[ j ][ k ] % MOD7 ) %= MOD7; return c; } vvi mat_pow( vvi a, ll p ){ vvi res = vvi( a.size(), vi( a.size() ) ); for( int i = 0; i < a.size(); ++i ) res[ i ][ i ] = 1; while( p ){ if( p & 1LL ) res = mat_mul( res, a ); p >>= 1; a = mat_mul( a, a ); } return res; } int int_pow( int v, int p ){ int res = v != 0; while( p ){ if( p & 1 ) res = 1LL * res * v % MOD7; p >>= 1; v = 1LL * v * v % MOD7; } return res; } void solve(){ int ans = 1; for( int i = 0; i < N; ++i ) ans = 1LL * ans * int_pow( mat_mul( mat_pow( trans, C[ i ] - 1 ), s1 )[ 0 ][ 0 ], d[ i ] ) % MOD7; cout << ans << endl; } signed main(){ ios::sync_with_stdio( 0 ); init(); preprocess(); solve(); return 0; }