import java.util.*; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int d = sc.nextInt(); for (int i = 0; i < d; i++) { int n1 = sc.nextInt(); int n2 = sc.nextInt(); int m = sc.nextInt(); int[] arr = new int[m]; HashMap[] dp = new HashMap[m]; for (int j = 0; j < m; j++) { arr[j] = sc.nextInt(); dp[j] = new HashMap(); } System.out.println(dfw(m - 1, new Bamboo(n1, n2), arr, dp)); } } static int dfw(int idx, Bamboo bamboo, int[] arr, HashMap[] dp) { if (bamboo.n1 < 0) { return Integer.MIN_VALUE; } if (idx < 0) { return 0; } if (dp[idx].containsKey(bamboo)) { return dp[idx].get(bamboo); } int ans = Math.max(dfw(idx - 1, bamboo, arr, dp), Math.max(dfw(idx - 1, bamboo.useFirst(arr[idx]), arr, dp), dfw(idx - 1, bamboo.useLast(arr[idx]), arr, dp)) + 1); dp[idx].put(bamboo, ans); return ans; } static class Bamboo { int n1; int n2; public Bamboo(int n1, int n2) { this.n1 = Math.min(n1, n2); this.n2 = Math.max(n1, n2); } public int hashCode() { return n1 + n2; } public boolean equals(Object o) { Bamboo b = (Bamboo)o; return n1 == b.n1 && n2 == b.n2; } public Bamboo useFirst(int x) { return new Bamboo(n1 - x, n2); } public Bamboo useLast(int x) { return new Bamboo(n1, n2 - x); } } }