按题意模拟就好
ACcode:
#include <map>
#include <queue>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#define maxn 1000
using namespace std;
int main(){
int t,need;
char str[maxn];
char team[maxn];
int n,s,x,y,mod,ans,tmp,cnt;
scanf("%d",&t);
while(t--){
scanf("%d%d%d%d%d",&n,&s,&x,&y,&mod);
tmp=s;
for(int i=1;i<=n;++i){
scanf("%s%s%d%s",&team,&str,&need,&str);
while(1){
if(s>=need){
printf("%d pages for %s\n",need,team);
s-=need;
break;
}
else{
printf("%d pages for %s\n",s,team);
s=(tmp*x+y)%mod;
tmp=s;
}
}
}
printf("\n");
}
return 0;
}