#include // c #include // io #include #include #include #include // container #include #include #include #include #include #include // other #include #include #include #include #include using namespace std; typedef long long ll; typedef unsigned long long ull; #define ALL(c) (begin(c)),(end(c)) #define REP(i,n) FOR(i,0,n) #define REPr(i,n) FORr(i,0,n) #define FOR(i,l,r) for(int i=(int)(l);i<(int)(r);++i) #define FORr(i,l,r) for(int i=(int)(r)-1;i>=(int)(l);--i) #define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it) #define IN(l,v,r) ((l)<=(v) && (v)<(r)) #define UNIQUE(v) v.erase(unique(ALL(v)),v.end()) //debug #define DUMP(x) cerr << #x << " = " << (x) #define LINE() cerr<< " (L" << __LINE__ << ")" class range { private: struct Iter{ int v; int operator*(){return v;} bool operator!=(Iter& itr) {return v < itr.v;} void operator++() {++v;} }; Iter i, n; public: range(int n) : i({0}), n({n}) {} range(int i, int n) : i({i}), n({n}) {} Iter& begin() {return i;} Iter& end() {return n;} }; //input template istream& operator >> (istream& is,pair& p){is>>p.first>>p.second;return is;} template istream& operator >> (istream& is,tuple& t){is >> get<0>(t);return is;} template istream& operator >> (istream& is,tuple& t){is >> get<0>(t) >> get<1>(t);return is;} template istream& operator >> (istream& is,tuple& t){is >>get<0>(t)>>get<1>(t)>>get<2>(t);return is;} template istream& operator >> (istream& is,tuple& t){is >> get<0>(t)>>get<1>(t)>>get<2>(t)>>get<3>(t);return is;} template istream& operator >> (istream& is, const tuple& t){is >> get<0>(t) >> get<1>(t) >> get<2>(t) >> get<3>(t) >> get<4>(t);return is;} template istream& operator >> (istream& is, const tuple& t){is >> get<0>(t) >> get<1>(t) >> get<2>(t) >> get<3>(t) >> get<4>(t) >> get<5>(t);return is;} template istream& operator >> (istream& is, const tuple& t){is >> get<0>(t) >> get<1>(t) >> get<2>(t) >> get<3>(t) >> get<4>(t) >> get<5>(t) >> get<6>(t);return is;} template istream& operator >> (istream& is,vector& as){REP(i,as.size())is >>as[i];return is;} //output template ostream& operator << (ostream& os, const set& ss){for(auto a:ss){if(a!=ss.begin())os<<" "; os< ostream& operator << (ostream& os, const pair& p){os< ostream& operator << (ostream& os, const map& m){bool isF=true;for(auto& p:m){if(!isF)os< ostream& operator << (ostream& os, const tuple& t){os << get<0>(t);return os;} template ostream& operator << (ostream& os, const tuple& t){os << get<0>(t)<<" "<(t);return os;} template ostream& operator << (ostream& os, const tuple& t){os << get<0>(t)<<" "<(t)<<" "<(t);return os;} template ostream& operator << (ostream& os, const tuple& t){os << get<0>(t)<<" "<(t)<<" "<(t)<<" "<(t);return os;} template ostream& operator << (ostream& os, const tuple& t){os << get<0>(t)<<" "<(t)<<" "<(t)<<" "<(t)<<" "<(t);return os;} template ostream& operator << (ostream& os, const tuple& t){os << get<0>(t)<<" "<(t)<<" "<(t)<<" "<(t)<<" "<(t)<<" "<(t);return os;} template ostream& operator << (ostream& os, const tuple& t){os << get<0>(t)<<" "<(t)<<" "<(t)<<" "<(t)<<" "<(t)<<" "<(t)<<" "<(t);return os;} template ostream& operator << (ostream& os, const vector& as){REP(i,as.size()){if(i!=0)os<<" "; os< ostream& operator << (ostream& os, const vector>& as){REP(i,as.size()){if(i!=0)os< T INF(){assert(false);}; template<> int INF(){return 1<<28;}; template<> ll INF(){return 1LL<<58;}; template<> double INF(){return 1e16;}; template<> long double INF(){return 1e16;}; template T EPS(){assert(false);}; template<> int EPS(){return 1;}; template<> ll EPS(){return 1LL;}; template<> double EPS(){return 1e-8;}; template<> long double EPS(){return 1e-8;}; template T pmod(T v,U M){return (v%M+M)%M;} class Main{ public: void run(){ int A,B,N;cin >> A >> B >> N; int BA = 64; vector amap(N/BA+1),bmap(2*(N/BA+1)); for(int _:range(A)){ int x;cin >> x;x--; amap[x/BA] |= 1ull << (x%BA); } for(int _:range(B)){ int x;cin >> x;x--; bmap[x/BA] |= 1ull << (x%BA); } int q;cin >> q; vector> bmapshift(64,vector(2*(N/BA+1))); bmapshift[0]=bmap; for (int i:range(1,64)){ bmapshift[i][0] = (bmapshift[i - 1][0] << 1); for (int j:range(1,2*(N/BA+1))) bmapshift[i][j] = (bmapshift[i - 1][j] << 1) | (bmapshift[i - 1][j - 1] >> 63); } for(int u : range(q)){ int x = u/64,sh = u%64; int res = 0; for(int i:range(N/BA+1)){ cerr << res <