In the world of Cyberpunk, all paintings are done by using lasers. As a cyber painter, painting with lasers is your daily job.
You have a laser painting board with n rows and mm columns of laser emitters. The distance between rows is 1, and so is the distance between columns. Each laser emitter can emit a laser with a length of 0.5 in four directions. Specifically, you can set an integer between 0 and 15 as the state value for each laser emitter, which can be denoted by a four-bit binary number (X1X2X3X4)2 (For example, 11=(1011)2). The meaning of the state value is as follows:
The first line contains an integer T 1≤T≤104), indicating the number of test cases.
The first line of each test case contains two integers n and m (1≤n×m≤105), indicating the number of rows and columns of the laser emitters.
The second line of each test case contains 16 integers a0,a1,…,a15 (0≤ai≤n×m, ∑i=015ai=n×m), where a_iai indicates the number of integer ii.
It guaranteed that the sum of n×m over all test cases won't exceed 106.
3
2 2
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4
2 2
0 0 0 1 0 0 1 0 0 1 0 0 1 0 0 0
3 3
0 0 0 0 0 0 1 0 0 1 0 1 1 1 2 2
1
41666667
41699736