// Arup Guha
// 12/5/2019
// Code to break knapsack cipher for Homework 6

import java.util.*;
import java.math.*;

public class breakknapsack {

	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
	
		// Get public set values.
		BigInteger[] nums = new BigInteger[128];
		for (int i=0; i<128; i++) 
			nums[i] = new BigInteger(stdin.next());
		
		// Get mod.
		BigInteger mod = new BigInteger(stdin.next());
		
		// Trying candidates.
		ArrayList<BigInteger> wList = new ArrayList<BigInteger>();
		for (int i=2; i<10; i++) {
			BigInteger tmp = new BigInteger(""+i);
			if (tmp.gcd(mod).equals(BigInteger.ONE)) {
				wList.add(tmp.modInverse(mod).multiply(nums[0]).mod(mod));
				wList.add(tmp.modInverse(mod).multiply(nums[1]).mod(mod));
			}
		}
		
		// Of the candidates, see which ones create a super increasing set when multiplying by the public keys.
		// I played around with this until there was one candidate and that is what multby gets set to.
		BigInteger multby = null;
		for (BigInteger x: wList) {
			if (isSuperInc(x,nums,mod)) {
				if (!x.gcd(mod).equals(BigInteger.ONE)) continue;
				multby = x.modInverse(mod);
			}
		}
		
		// Here is the key.
		BigInteger[] key = new BigInteger[128];
		for (int i=0; i<nums.length; i++) 
			key[i] = nums[i].multiply(multby).mod(mod);
		
		// Now read in ciphertext and decrypt.
		int numBlocks = stdin.nextInt();
		for (int i=0; i<numBlocks; i++) {
			
			// Get cipher change to plain by multiplying by multby.
			BigInteger cipher = new BigInteger(stdin.next());
			BigInteger plain = cipher.multiply(multby).mod(mod);
			
			// Decode the plaintext!
			System.out.println(decode(plain,key));
		}
	}
	
	// This decodes the plaintext by using the greedy algorithm to solve subset sum 
	// on the super increasing set key.
	public static String decode(BigInteger plain, BigInteger[] key) {
		
		// Store result here.
		String res = "";
		
		// 16 bytes, sorry I hard-coded!
		for (int i=15; i>=0; i--) {
			
			// 8 bits again, sorry I hard coded!
			int val = 0;
			for (int j=7; j>=0; j--) {
				
				// It's big enough, so it's a 1 bit.
				if (key[i*8+j].compareTo(plain) <= 0) {
					
					// Add to our ascii value.
					val += (1<<(7-j));
					
					// Subtract from our running plaintext.
					plain = plain.subtract(key[i*8+j]);
				}
			}
			
			// This is the character to add to the end.
			res = (char)(val) + res;
		}
		
		// Ta da!
		return res;
	}
	
	// Returns true iff xinv*list[i] creates a super increasing list.
	public static boolean isSuperInc(BigInteger x, BigInteger[] list, BigInteger mod) {
		
		// Skip this.
		if (!x.gcd(mod).equals(BigInteger.ONE)) return false;
		
		// Init values.
		BigInteger sum = new BigInteger("0");
		BigInteger xinv = x.modInverse(mod);
		
		// Go through the list.
		for (int i=0; i<list.length; i++) {
			
			// This would be the super-increasing set value.
			BigInteger val = xinv.multiply(list[i]).mod(mod);
			
			// This is bad because the old sum is >= to the new value.
			if (sum.compareTo(val) >= 0)
				return false;
			
			// Update the sum.
			sum = sum.add(val);
		}
		
		// If we get here, we are good.
		return true;
	}
}