#include <bits/stdc++.h>

 #define int long long
 #define pa pair<int,int>
 #define ll long long
  #define  mp make_pair
  #define  pb push_back


using namespace std;



int a[200020],b[200020];
int la[200020],lb[200020];
int fix_a[200020],fix_b[200020];
int inv_a[200020];

int keta(int val){
	int ANS=0;
	while(val){
		val/=10;
		ANS++;
	}
	return ANS;
}


const ll ten17=100000000000000000ll;

int shoukei[200020];
int ans[2000020];

vector<pa> sub[200020];
struct segsum{
	
	private:
	public:
	vector<int> BIT;
	int N;
	void shoki1(int n){
		BIT.resize(n+1,0);
		N=n;
		while(N!=(N&-N))N-=(N&-N);
	}
	void shoki(int n){
		for(int i=1;i<n;i++)if(i+(i&-i)<=n)BIT[i+(i&-i)]+=BIT[i];
	}

	void add(int x,int w,int n){
		for(int i=x+1;i<=n;i+=i&-i)BIT[i]+=w;
	}
	int sum(int e){
		int wa=0;
		for(int i=e;i>0;i-=i&-i)wa+=BIT[i];
		return wa;
	}
	pa lowerbound(int w,int f,int n){
		int x=0;
		for(int i=N;i>0;i>>=1){
			if(x+i<=n && BIT[x+i]+i*f<w){
				w-= BIT[x+i]+i*f;
				x|=i;
			}
		}
		
		return mp(x,w);
	}

};
segsum ss;


 signed main(){
 	

    	       cin.tie(0);
   			ios::sync_with_stdio(false);
int n,m;
 	cin>>n>>m;
 		vector<pair<pa,int>> ve;
 int keta_sum_b=0;
 	
 	for(int i=0;i<n;i++){
 		cin>>a[i];
 	}
 	for(int i=0;i<m;i++){
 		cin>>b[i];
 	}
 	

 	for(int i=0;i<n;i++){
 		
 		la[i]=keta(a[i]);
 		fix_a[i]=a[i];
 		if(a[i]==1000000000){
 			fix_a[i]=a[i]/10;
 		}
 		else{
 			while(fix_a[i]<100000000)fix_a[i]*=10;
 		}
 		inv_a[i]= (ten17)/fix_a[i]+!!((ten17)%fix_a[i]);
 		ve.pb(mp(mp(inv_a[i],0),i));
 	}
 	for(int i=0;i<m;i++){
 		
 		lb[i]=keta(b[i]);
 		keta_sum_b+=lb[i]-1;
 		fix_b[i]=b[i];
 		if(b[i]==1000000000){
 			fix_b[i]=b[i]/10;
 		}
 		else{
 			while(fix_b[i]<100000000)fix_b[i]*=10;
 		}
 		
 		ve.pb(mp(mp(fix_b[i],1),i));
 	}
 		
 	sort(ve.begin(),ve.end());
 	
 //	for(auto v:ve)cout<<v.first.first<<" "<<v.first.second<<" "<<v.second<<endl;
 	int cnt=0;
 	for(auto v:ve){
 		//cout<<v.first.first<<endl;
 		if(v.first.second==0){
 			
 			shoukei[v.second]=m-cnt+keta_sum_b+m*la[v.second];
 		}
 		else{
 			cnt++;
 		}
 	}
 	
 	vector<int> rui(n);
 	rui[0]=shoukei[0];
 	for(int i=1;i<n;i++)rui[i]=rui[i-1]+shoukei[i];
 	
// 	for(int i=0;i<n;i++)cout<<shoukei[i]<<endl;
 	
 	int Q;
 	cin>>Q;
 	//Q=2000000;
 	//
 	//cout<<Q<<endl;
 	vector<int> query;
 	for(int i=1;i<=Q;i++){
 		int y;
 		cin>>y;
 		query.pb(y);
 	}
 	
 	//
 //	cout<<rui.back()<<endl;
 	for(int i=0;i<Q;i++){
 		if(query[i]>rui.back()){
 			ans[i]=-1;
 			
 		
 		}
 		else{
 			int it=lower_bound(rui.begin(),rui.end(),query[i])-rui.begin();
 			int sa;
 			if(it==0) sa=query[i];
 			else sa=query[i]-rui[it-1];
 				sub[it].pb({sa,i});
 	//		cout<<i<<" "<<it<<" "<<sa<<endl;
 		}
 		
 	}
 	ss.shoki1(m);
 	for(int i=0;i<m;i++){
 		ss.BIT[i+1]=lb[i];
 	}
 //	return 0;
 	ss.shoki(m);
 	int ju[20];
 	ju[0]=1;
 	for(int i=1;i<20;i++)ju[i]=ju[i-1]*10ll;
 	for(auto v:ve){
 //		cout<<" "<<v.first.first<<" "<<v.first.second<<" "<<v.second<<endl;
 		if(v.first.second==1){
 			ss.add(v.second,-1,m);
 		}
 		else{
 			
 			for(auto w:sub[v.second]){
 				

 				
 				
 				pa z=ss.lowerbound(w.first,la[v.second],m);
				//cout<<z.first<<" "<<z.second<<endl;
 				int val=a[v.second]*b[z.first];
 				/*
 				int ke=la[v.second]+lb[z.first];
 				if(fix_a[v.second]*fix_b[z.first]<ten_17)ke--;
 				*/
 				int ke=keta(val);
 				//for(int i=0;i<ke-z.second;i++)val/=10;
 				ans[w.second]=val/ju[ke-z.second]%10;
 				
 			}
 		}
 	}
 	
 	for(int i=0;i<Q;i++){
 		if(ans[i]>=0) cout<<ans[i];
 		else cout<<"x";
 	}
cout<<endl;
 	return 0;

  }


Measured memory_bytes: 31872