#include using namespace std; typedef int ll; #define int long long #define ff first #define ss second #define pb push_back #define mp make_pair #define sz(x) ((int)x.size()) #define all(x) x.begin(),x.end() #define endl '\n' #define fpos adla typedef pairpii; typedef pair > piii; const int mod=1e9+7; int POWER[65]; int power(int a, int b) {int ret=1;while(b) {if(b&1) ret*=a;a*=a;if(ret>=mod) ret%=mod;if(a>=mod) a%=mod;b>>=1;}return ret;} int inv(int x) {return power(x,mod-2);} void precompute() { POWER[0]=1; for(int i=1;i<63;i++) POWER[i]=POWER[i-1]<<1LL; } const int inf = 1e9; const int maxn = 1e6+55; char s[maxn]; map to[maxn]; int len[maxn], fpos[maxn], link[maxn],leaf[maxn],bkl[maxn]; int node, pos; string str; int sz = 1, n = 0; int make_node(int _pos, int _len) { //cout< len[to[node][s[n - pos]]]) { // cout< 0) { // cout<<"zzzzzzz\n"; go_edge(); int edge = s[n - pos]; int &v = to[node][edge]; int t = s[fpos[v] + pos - 1]; if(v == 0) { // cout<<"xx "<vv; int totsu=0; pii vv1[maxn],vw[maxn]; void dfs(int curr , int pre , int _len) { int nlen=_len; int val=len[curr]; if(val>n) val=n-fpos[curr]; if(curr!=0) nlen+=val; for (char c='a' ; c<='z' ; c++) { int px=c; if(to[curr].find(px)==to[curr].end()) continue; dfs(to[curr][px],curr,nlen); leaf[curr]+=leaf[to[curr][px]]; bkl[curr]=bkl[to[curr][px]]; } char c='$'; int px=c; if(to[curr].find(px)!=to[curr].end()) { dfs(to[curr][px],curr,nlen); leaf[curr]+=leaf[to[curr][px]]; bkl[curr]=bkl[to[curr][px]]; } if(sz(to[curr])==0) { bkl[curr]=nlen; leaf[curr]=1; } //cout<n) val=n-fpos[curr]; if(curr!=0) nlen+=val; int st=n-bkl[curr]; if(curr!=0) { vw[curr]=mp(st,nlen); } // cout<n) val=n-fpos[curr]; if(curr!=0) nlen+=val; int st=n-bkl[curr]; // cout<> str; str+='$'; int ans = 0; for(int i = 0; i < str.size(); i++) { // cout<>q; int g=0; while (q--) { int p,m; cin>>p>>m; p%=m; int x=(p*g)%m+1; // cout<=fnd) { ret=mid; hi=mid-1; } else lo=mid+1; } // cout<