/* Sample solution to Pizza delivery * Author: Mikael Goldmann * * Method: Solve independently for x and y coordinates * */ import java.io.*; import java.util.*; class pizza { static BufferedReader stdin; static PrintWriter stdout; public static void main(String[] ss) throws Exception { Reader rdr = new InputStreamReader(System.in); stdin = new BufferedReader(rdr); Writer wtr = new OutputStreamWriter(System.out); wtr = new BufferedWriter(wtr); stdout = new PrintWriter(wtr); (new pizza()).run(); stdout.close(); } void run() throws Exception { int N = Integer.parseInt(stdin.readLine()); for (int i = 0; i < N; ++i) solve(i+1); } void solve(int cnt) throws Exception { int X,Y; StringTokenizer st = new StringTokenizer(stdin.readLine()); X = Integer.parseInt(st.nextToken()); Y = Integer.parseInt(st.nextToken()); int[] xs = new int[X]; int[] ys = new int[Y]; for (int y=0; y < Y; ++y) { st = new StringTokenizer(stdin.readLine()); for (int x=0; x < X; ++x) { int d = Integer.parseInt(st.nextToken()); xs[x] += d; ys[y] += d; } } stdout.println(opt(xs)+opt(ys) + " blocks"); } int opt(int[] v) { int n = v.length; int[] s = new int[n]; s[0] = v[0]; int cost=0; for (int i = 1; i < n; ++i) { cost += i*v[i]; s[i] = s[i-1]+v[i]; } for (int j = 0; 2*s[j] < s[n-1]; ++j) cost -= s[n-1]-2*s[j]; return cost; } }