#include #include #include #include #include//pair #include//greater #include #include #include #include #include #define F first #define S second #define sd(n) scanf("%d",&n) #define sdd(m,n) scanf("%d %d",&m,&n) #define sl(n) scanf("%lld",&n) #define sll(m,n) scanf("%lld %lld",&m,&n) #define sc(n) scanf("%c",&n) #define ss(n) scanf("%s",n) #define pd(n) printf("%d\n",n) #define pl(n) printf("%lld\n",n) #define pc(n) printf("%c ",n) #define ps(n) printf("%s ",n) #define NL printf("\n") #define pb(n) push_back(n) #define sz size() #define clr(v,a,b) for(int i=a;i<=b;i++)v[i].clear() #define all(v) v.begin(),v.end() #define mod 1000000007//10^9+7 #define pp(a,b) make_pair(a,b) /*#include ifstream fin("in.txt"); ofstream fout("out.txt");*/ using namespace std; typedef long long ll; typedef pair pii; typedef pair pll; const int MXN=100005; //two approach for storing more than two values-node structure and separate arrays ll ar[100005]; ll ia[100005]; ll mb[100005]; struct bit { ll a[MXN]; bit() { memset(a,0,sizeof(a)); } void upd(int i,ll x,int n) { if(i==0) {a[0]=(a[0]+x+mod)%mod;return;} while(i<=n) { a[i]=(a[i]+x+mod)%mod; i+=i & -i; } } ll sum(int i) { ll s=0; while(i>0) { s=(s+a[i])%mod; i-= i & -i; } s=(s+a[0])%mod; return s; } }; long long fpow(long long x,long long n) { long long r=1; while(n>0) { if(n%2) { r=(r*x)%mod; } x=(x*x)%mod; n/=2; } return r; } int main() { //int a[10]={3,5,2,5,8,1,5,0,9,4}; ll n,a,b,q; sl(n);sll(a,b);sl(q); int bb=mod-b; ia[0]=1;mb[0]=1; ia[1]=fpow(a,mod-2); mb[1]=bb; for(int i=2;i<=n+2;i++) { ia[i]=(ia[1]*ia[i-1])%mod; mb[i]=(bb*mb[i-1])%mod; } bit tr; for(int i=0;i0) ans=(ans-tr.sum(p-1)+mod)%mod; ll px=(mb[p]*ia[p])%mod; ll iv=fpow(px,mod-2); ans=(ans*iv)%mod; if(ans==0) printf("Yes\n"); else printf("No\n"); } } return 0; }