#include using namespace std; #include using namespace atcoder; using mint = modint998244353; using ll = long long; using ull = unsigned long long; #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) random_device rnd; mt19937 mt(rnd()); int RandInt(int a, int b) { return a + mt() % (b - a + 1); } const int dx[4] = {0, 1, 0, -1}; const int dy[4] = {1, 0, -1, 0}; int n; string s,t; int s_sz,t_sz; pair f(int x) { int s_cnt = x / s_sz; int nokori = x % s_sz; if (nokori % t_sz == 0) { int t_cnt = nokori / t_sz; return {s_cnt, t_cnt}; }else{ while (s_cnt > 0) { s_cnt--; nokori += s_sz; if (nokori % t_sz == 0) { int t_cnt = nokori / t_sz; return {s_cnt, t_cnt}; } } } return {-1, -1}; } int main(){ cin>>n>>s>>t; s_sz=s.size(); t_sz=t.size(); rep(i,n){ int x; cin>>x; pairp=f(x); //cerr<