- //乘法逆元 多取模
- #include
- using namespace std;
- using ll = long long;
- const int N = 2e6 + 9;
- const ll p = 998244353;//取模的值
-
- ll qmi(ll a, ll b)//快速幂模板
- {
- ll res = 1;
- while (b)
- {
- if (b & 1) res = res * a % p;//b为奇数,实际上还要进行b--,变为一个偶数
- a = a * a % p, b >>= 1;//b为偶数
- }
- return res;
- }
-
- ll inv(ll x) { return qmi(x, p - 2); }//逆元模板
-
- ll f(ll a, ll b, ll c, ll x)
- {
- return (a * x % p + b) % p * inv(c * x % p) % p;//因为乘法的封闭性所可以在括号里面取mod
- }
-
- void slove()
- {
- ll a, b, c; cin >> a >> b >> c;
- ll q; cin >> q;
-
- while (q--)
- {
- ll x; cin >> x;
- cout << f(a, b, c, x) << '\n';
- }
- }
-
- int main()
- {
- ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
- int t; cin >> t;
- while (t--)slove();
- return 0;
- }