• Source
    1. #include<bits/stdc++.h>
    2. #define ll long long
    3. #define loop(i,n) for(i=0;i<n;++i)
    4. #define loop1(i,n,x) for(i=x;i<n;++i)
    5. #define loopr(i,n) for(i=n;i>=0;--i)
    6. using namespace std;
    7. typedef vector<int> vi;
    8. ll M=1e9+7;
    9. int main()
    10. {
    11. int t;
    12. cin>>t;
    13. while(t){
    14. --t;
    15. ll a,b,c,d,m;
    16. cin>>a>>b>>c>>d>>m;
    17. long n;
    18. cin>>n;
    19. long i;
    20. a=(a+m)%m;
    21. b=(b+m)%m;
    22. c=(c+m)%m;
    23. d=(d+m)%m;
    24. unordered_map<ll,int>mp;
    25. ll temp;
    26. ll arr[n];
    27. loop(i,n){
    28. cin>>arr[i];
    29. temp=arr[i];
    30. temp=(temp+m)%m;
    31. temp=(temp*temp)%m;
    32. mp.insert({temp,1});
    33. }
    34. ll ans=0;
    35. loop(i,n){
    36. temp=(arr[i]+m)%m;
    37. ll t1=(temp*temp)%m;
    38. ll t2=t1;
    39. t1=((t1%m)*(temp))%m;
    40. t1=((a)*(t1%m))%m;
    41. t2=((t2%m)*(b))%m;
    42. temp=(temp*c)%m;
    43. ll fd=(t1+t2+temp+d)%m;
    44. if(mp.find(fd)!=mp.end()){
    45. ans++;
    46. ans%=M;
    47. }
    48. }
    49. cout<<ans%M<<endl;
    50. }
    51. }
    52.