import java.util.*;
class Solution
{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int T = sc.nextInt();
for (int test_case = 1; test_case <= T; test_case++) {
ArrayList<Integer> list = new ArrayList<>();
int a_size = sc.nextInt();
int b_size = sc.nextInt();
int [] A = new int[a_size];
int [] B = new int[b_size];
for (int i = 0; i < a_size; i++) {
A[i] = sc.nextInt();
}
for (int i = 0; i < b_size; i++) {
B[i] = sc.nextInt();
}
// ๋ ๋ฐฐ์ด ์ค ๋ญ๊ฐ ๋ ๊ธด ์ง ํ์ธํ๋ค.
if(A.length> B.length){
multiply(list, B,A);
}else {
multiply(list,A,B);
}
// list ์ค ์ ์ผ ํฐ ๊ฐ ์ถ๋ ฅ
System.out.println("#"+test_case+" "+(list.stream().max(new Comparator<Integer>() {
@Override
public int compare(Integer o1, Integer o2) {
return o1 -o2;
}
}).orElse(0)));
}
}
static void multiply (ArrayList<Integer> list, int small[], int big[]) { // ์์ ๋ฐฐ์ด์ ์ด๋์์ผ๊ฐ๋ฉฐ ๊ณ์ฐ temp์ ๊ฒฐ๊ณผ ์ ์ฅ
for (int j = 0; j <= big.length- small.length; j++)
{
int temp = 0;
for (int i = 0; i < small.length; i++) {
temp += small[i] * big[i+j];
}
list.add(temp);
temp = 0;
}
}
}
0