#include <iostream>
#include <vector>
#include <array>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <tuple>
#include <bitset>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <fstream>
constexpr long long int power(const long long int base, const int exp) {
	switch (exp) {
	case 0: return 1;
	case 1: return base;
	default: return power(base * base, exp / 2) * power(base, exp % 2);
	}
}
char get_digit(long long int number, const long long int digit) {
	int count = 0;
	for (auto n = number; n > 0; n /= 10) ++count;
	for (int i = count - digit; i > 0; --i) {
		number /= 10;
	}
	return number % 10 + '0';
}
int main() {
	std::cin.tie(0); std::cin.sync_with_stdio(false);
	constexpr std::array<long long int, 19> digits{ power(10, 0), power(10, 1), power(10, 2), power(10, 3), power(10, 4), power(10, 5), power(10, 6), power(10, 7), power(10, 8), power(10, 9), power(10, 10), power(10, 11), power(10, 12), power(10, 13), power(10, 14), power(10, 15), power(10, 16), power(10, 17), power(10, 18) };
	int n, m; std::cin >> n >> m;
	std::vector<int> row(n), column(m);
	for (auto& r : row) std::cin >> r;
	for (auto& c : column) std::cin >> c;
	std::vector<std::vector<int>> sub_array(m);
	for (auto i = 0; i < m; ++i) {
		for (auto position = i; position < sub_array.size(); position += ~position & (position + 1)) {
			sub_array[position].push_back(column[i]);
		}
		std::sort(sub_array[i].begin(), sub_array[i].end());
	}
	auto column_sorted = column;
	std::sort(column_sorted.begin(), column_sorted.end());
	std::vector<long long int> digit_by_row; digit_by_row.reserve(n);
	for (const auto r : row) {
		int digit_count = 0;
		int count = 0;
		for (auto digit = 1; digit <= 19; ++digit) {
			auto upper = std::upper_bound(std::next(column_sorted.begin(), count), column_sorted.end(), (digits[digit - 1] - 1) / r);
			if (upper == column_sorted.end()) break;
			digit_count += std::distance(upper, column_sorted.end());
			count = std::distance(column_sorted.begin(), upper);
		}
		digit_by_row.push_back(digit_count);
	}
	for (auto i = 1; i < n; ++i) digit_by_row[i] += digit_by_row[i - 1];
	int max_bit = 1;
	for (auto i = m; i > 1; i >>= 1) max_bit <<= 1;
	int q; std::cin >> q;
	//std::string result; result.reserve(q);
	for (auto _i = 0; _i < q; ++_i) {
		long long int d; std::cin >> d;
		if (d > digit_by_row.back()) {
			//result.push_back('x');
			std::cout << 'x';
			continue;
		}
		auto row_count = std::distance(digit_by_row.begin(), std::lower_bound(digit_by_row.begin(), digit_by_row.end(), d));
		if (row_count != 0) d -= digit_by_row[row_count - 1];
		const long long int r = row[row_count];
		int column_pos = 0;
		for (int pos = max_bit - 1; pos >= 0; pos = ((pos + 1) >> 1) - 1) if (column_pos + pos < sub_array.size()) {
			int digit_count = 0;
			int count = 0;
			for (auto digit = 1; digit <= 19; ++digit) {
				auto upper = std::upper_bound(std::next(sub_array[column_pos + pos].begin(), count), sub_array[column_pos + pos].end(), (digits[digit - 1] - 1) / r);
				if (upper == sub_array[column_pos + pos].end()) break;
				digit_count += std::distance(upper, sub_array[column_pos + pos].end());
				if (digit_count >= d) break;
				count = std::distance(sub_array[column_pos + pos].begin(), upper);
			}
			if (digit_count < d) {
				column_pos += pos + 1;
				d -= digit_count;
			}
		}
		std::cout << get_digit(r * column[column_pos], d);
		//result.push_back(get_digit(r * column[column_pos], d));
	}
	//std::cout << result << '\n';
	std::cout << '\n';
}



Measured memory_bytes: 12916