public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		while ((line = in.readLine()) != null && line.length() != 0) {
			int times = Integer.parseInt(line.trim());
			int amount = 0;
			for (int i = 0; i < times; i++) {
				amount = Integer.parseInt(in.readLine().trim());
				int nCoins = Integer.parseInt(in.readLine().trim()), sum = 0;
				V = new int[nCoins];
				for (int j = 0; j < nCoins; j++) {
					V[j] = Integer.parseInt(in.readLine().trim());
					if (sum < amount)
						sum += V[j];
				}
				Arrays.sort(V);
				int index = fillMinCost(sum, amount);
				out.append(index + " " + minCost[index] + "\n");
			}
		}
		System.out.print(out);
	}