//乘法逆元 多取模
#include<iostream>
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;
}
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;
}