/// <reference path="typings/lodash/lodash.d.ts" />
/// <reference path="typings/d8/d8.d.ts" />
function ints() {
    var s = readline();
    return s.split(' ').map(function (x) { return parseInt(x); });
}
function array(length, value) {
    var result = new Array(length);
    for (var i = 0; i < length; i++) {
        result[i] = value();
    }
    return result;
}
var _a = ints(), n = _a[0], m = _a[1];
var adj = array(n + 1, function () { return array(n + 1, function () { return false; }); });
var edges = [];
var degree = array(n + 1, function () { return 0; });
for (var i = 0; i < m; i++) {
    var _b = ints(), a = _b[0], b = _b[1];
    adj[a][b] = true;
    adj[b][a] = true;
    ++degree[a];
    ++degree[b];
    edges.push({ first: a, second: b });
}
var best = 6000;
for (var _i = 0; _i < edges.length; _i++) {
    var x = edges[_i];
    var first = x.first, second = x.second;
    for (var i = 1; i <= n; i++) {
        if (first != i && second != i && adj[first][i] && adj[second][i]) {
            var current = degree[first] + degree[second] + degree[i];
            if (best > current)
                best = current;
        }
    }
}
if (best == 6000)
    best = -1;
else
    best -= 6;
print(best);

/* TEST CASE
input
5 6
1 2
1 3
2 3
2 4
3 4
4 5
output
2

input
7 4
2 1
3 6
5 1
1 7
output
-1

*/
function minimumSumOfRecogitions(nodes) {
	var ret = Infinity;
	var n = nodes.length;
	var i, j, k;
	var sorter = function (v1, v2) {return v1.neighbors.length - v2.neighbors.length;};
	for (i = 0; i < n; i++) {
		nodes[i].neighbors.sort(sorter);
	}
	nodes.sort(sorter);

	for (i = 0; i < n; i++) {
		var node1 = nodes[i];
		if (node1.neighbors.length - 2 >= ret) {
			break;
		}
		for (j = 0; j < node1.neighbors.length; j++) {
			var node2 = node1.neighbors[j];

			if (node1.neighbors.length + node2.neighbors.length - 4 >= ret) {
				break;
			}
			for (k = 0; k < node2.neighbors.length; k++) {
				var node3 = node2.neighbors[k];
				if (node3.adjMap[node1.nodeIndex] != null)
					ret = Math.min(ret, node1.neighbors.length + node2.neighbors.length + node3.neighbors.length - 6);
			}
		}
	}

	return ret == Infinity ? -1 : ret;
}

function main() {
	var splitted = readline().split(' ');
	var n = parseInt(splitted[0]);
	var m = parseInt(splitted[1]);
	var nodes = new Array(n);
	var i;
	var u, v;
	var dummyObj = {};

	for (u = 0; u < n; u++) {
		nodes[u] = {nodeIndex: u, neighbors: [], adjMap: {}};
	}
	for (i = 0; i < m; i++) {
		splitted = readline().split(' ');
		u = parseInt(splitted[0]) - 1;
		v = parseInt(splitted[1]) - 1;
		if (u != v) {
			nodes[u].adjMap[v] = dummyObj;
			nodes[v].adjMap[u] = dummyObj;
			nodes[u].neighbors.push(nodes[v]);
			nodes[v].neighbors.push(nodes[u]);
		}
	}

	var answer = minimumSumOfRecogitions(nodes);
	print(answer);
}

main();

/* TEST CASE
input
5 6
1 2
1 3
2 3
2 4
3 4
4 5
output
2

input
7 4
2 1
3 6
5 1
1 7
output
-1

*/
function minimumSumOfRecogitions(nodes) {
	var ret = Infinity;
	var n = nodes.length;
	var i, j, k;
	var sorter = function (v1, v2) {return v1.neighbors.length - v2.neighbors.length;};
//	for (i = 0; i < n; i++) {
//		nodes[i].neighbors.sort(sorter);
//	}
	nodes.sort(sorter);

	for (i = 0; i < n; i++) {
		var node1 = nodes[i];
		if (node1.neighbors.length - 2 >= ret) {
			break;
		}
		for (j = 0; j < node1.neighbors.length; j++) {
			var node2 = node1.neighbors[j];

			if (node1.neighbors.length + node2.neighbors.length - 4 < ret) {
				for (k = 0; k < node2.neighbors.length; k++) {
					var node3 = node2.neighbors[k];
					if (node3.adjMap[node1.nodeIndex] != null)
						ret = Math.min(ret, node1.neighbors.length + node2.neighbors.length + node3.neighbors.length - 6);
				}
			}
		}
	}

	return ret == Infinity ? -1 : ret;
}

function main() {
	var splitted = readline().split(' ');
	var n = parseInt(splitted[0]);
	var m = parseInt(splitted[1]);
	var nodes = new Array(n);
	var i;
	var u, v;
	var dummyObj = {};

	for (u = 0; u < n; u++) {
		nodes[u] = {nodeIndex: u, neighbors: [], adjMap: {}};
	}
	for (i = 0; i < m; i++) {
		splitted = readline().split(' ');
		u = parseInt(splitted[0]) - 1;
		v = parseInt(splitted[1]) - 1;
		if (u != v) {
			nodes[u].adjMap[v] = dummyObj;
			nodes[v].adjMap[u] = dummyObj;
			nodes[u].neighbors.push(nodes[v]);
			nodes[v].neighbors.push(nodes[u]);
		}
	}

	var answer = minimumSumOfRecogitions(nodes);
	print(answer);
}

main();

/* TEST CASE
input
5 6
1 2
1 3
2 3
2 4
3 4
4 5
output
2

input
7 4
2 1
3 6
5 1
1 7
output
-1

*/
function minimumSumOfRecogitions(nodes) {
	var ret = Infinity;
	var n = nodes.length;
	var i, j, k;

	for (i = 0; i < n; i++) {
		var node1 = nodes[i];
		var n1 = node1.neighbors.length;
		if (n1 - 2 < ret) {
			for (j = 0; j < n1; j++) {
				var node2 = node1.neighbors[j];
				var n2 = node2.neighbors.length;

				if (n1 + n2 - 4 < ret) {
					for (k = 0; k < node2.neighbors.length; k++) {
						var node3 = node2.neighbors[k];
						if (node3.adjMap[node1.nodeIndex] != null) {
							ret = Math.min(ret, n1 + n2 + node3.neighbors.length - 6);
						}
					}
				}
			}
		}
	}

	return ret == Infinity ? -1 : ret;
}

function main() {
	var splitted = readline().split(' ');
	var n = parseInt(splitted[0]);
	var m = parseInt(splitted[1]);
	var nodes = new Array(n);
	var i;
	var u, v;
	var dummyObj = {};

	for (u = 0; u < n; u++) {
		nodes[u] = {nodeIndex: u, neighbors: [], adjMap: {}};
	}
	for (i = 0; i < m; i++) {
		splitted = readline().split(' ');
		u = parseInt(splitted[0]) - 1;
		v = parseInt(splitted[1]) - 1;
		if (u != v) {
			nodes[u].adjMap[v] = dummyObj;
			nodes[v].adjMap[u] = dummyObj;
			nodes[u].neighbors.push(nodes[v]);
			nodes[v].neighbors.push(nodes[u]);
		}
	}

	var answer = minimumSumOfRecogitions(nodes);
	print(answer);
}

main();

/* TEST CASE
input
5 6
1 2
1 3
2 3
2 4
3 4
4 5
output
2

input
7 4
2 1
3 6
5 1
1 7
output
-1

*/
function minimumSumOfRecogitions(nodes) {
	var ret = Infinity;
	var n = nodes.length;
	var i, j, k;

	for (i = 0; i < n; i++) {
		var node1 = nodes[i];
		var n1 = node1.neighbors.length;
		if (n1 - 2 < ret) {
			for (j = 0; j < n1; j++) {
				var node2 = node1.neighbors[j];
				var n2 = node2.neighbors.length;

				if (n1 + n2 - 4 < ret) {
					for (k = 0; k < n2; k++) {
						var node3 = node2.neighbors[k];
						if (node3.adjMap[node1.nodeIndex] != null) {
							ret = Math.min(ret, n1 + n2 + node3.neighbors.length - 6);
						}
					}
				}
			}
		}
	}

	return ret < Infinity ? ret : -1;
}

function main() {
	var splitted = readline().split(' ');
	var n = parseInt(splitted[0]);
	var m = parseInt(splitted[1]);
	var nodes = new Array(n);
	var i;
	var u, v;
	var dummyObj = {};

	for (u = 0; u < n; u++) {
		nodes[u] = {nodeIndex: u, neighbors: [], adjMap: {}};
	}
	for (i = 0; i < m; i++) {
		splitted = readline().split(' ');
		u = parseInt(splitted[0]) - 1;
		v = parseInt(splitted[1]) - 1;
		if (u != v) {
			nodes[u].adjMap[v] = dummyObj;
			nodes[v].adjMap[u] = dummyObj;
			nodes[u].neighbors.push(nodes[v]);
			nodes[v].neighbors.push(nodes[u]);
		}
	}

	var answer = minimumSumOfRecogitions(nodes);
	print(answer);
}

main();

/* TEST CASE
input
5 6
1 2
1 3
2 3
2 4
3 4
4 5
output
2

input
7 4
2 1
3 6
5 1
1 7
output
-1

*/
function minimumSumOfRecogitions(nodes) {
	var ret = Infinity;
	var n = nodes.length;
	var i, j, k;

	for (i = 0; i < n; i++) {
		var node1 = nodes[i];
		if (node1.neighbors.length - 2 < ret) {
			for (j = 0; j < node1.neighbors.length; j++) {
				var node2 = node1.neighbors[j];

				if (node1.neighbors.length + node2.neighbors.length - 4 < ret) {
					for (k = 0; k < node2.neighbors.length; k++) {
						var node3 = node2.neighbors[k];
						if (node3.adjMap[node1.nodeIndex] != null) {
							var newRecognitions = node1.neighbors.length + node2.neighbors.length + node3.neighbors.length - 6;
							if (ret > newRecognitions) {
								ret = newRecognitions;
							}
						}
					}
				}
			}
		}
	}

	return ret == Infinity ? -1 : ret;
}

function main() {
	var splitted = readline().split(' ');
	var n = parseInt(splitted[0]);
	var m = parseInt(splitted[1]);
	var nodes = new Array(n);
	var i;
	var u, v;
	var dummyObj = {};

	for (u = 0; u < n; u++) {
		nodes[u] = {nodeIndex: u, neighbors: [], adjMap: {}};
	}
	for (i = 0; i < m; i++) {
		splitted = readline().split(' ');
		u = parseInt(splitted[0]) - 1;
		v = parseInt(splitted[1]) - 1;
		if (u != v) {
			nodes[u].adjMap[v] = dummyObj;
			nodes[v].adjMap[u] = dummyObj;
			nodes[u].neighbors.push(nodes[v]);
			nodes[v].neighbors.push(nodes[u]);
		}
	}

	var answer = minimumSumOfRecogitions(nodes);
	print(answer);
}

main();

var input = readline().split(' ');
var n = parseInt(input[0], 10);
var m = parseInt(input[1], 10);

warriors = [];
deg = [];

for(var i = 0; i < n; i++) {
    var fill = [];
    for(var j = 0; j < n; j++) {
        fill.push(false);
    }
    warriors.push(fill);
    deg.push(0);
}

for(var i = 0; i < m; i++) {
    input = readline().split(' ');
    var a = parseInt(input[0], 10);
    var b = parseInt(input[1], 10);
    warriors[a - 1][b - 1] = true;
    warriors[b - 1][a - 1] = true;
    deg[a - 1] += 1;
    deg[b - 1] += 1;
}

var result = 100000000000;

for(var i = 0; i < n; i++) {
    for(var j = i + 1; j < n; j++) {
        if (warriors[i][j]) {
            for(var k = j + 1; k < n; k++) {
                if (warriors[i][k] && warriors[j][k]) {
                    var sum = deg[i] + deg[j] + deg[k];
                    result = Math.min(result, sum);
                }
            }
        }
    }
}

result === 100000000000 ? print('-1') : print(result - 6);

/* TEST CASE
input
5 6
1 2
1 3
2 3
2 4
3 4
4 5
output
2

input
7 4
2 1
3 6
5 1
1 7
output
-1

*/
function minimumSumOfRecogitions(nodes, adjMap) {
	var ret = Infinity;
	var n = nodes.length;
	var i, j, k;
//	var sorter = function (v1, v2) {return v1.neighbors.length - v2.neighbors.length;};
//	for (i = 0; i < n; i++) {
//		nodes[i].neighbors.sort(sorter);
//	}
//	nodes.sort(sorter);

	for (i = 0; i < n; i++) {
		var node1 = nodes[i];
		if (node1.neighbors.length - 2 < ret) {
			for (j = 0; j < node1.neighbors.length; j++) {
				var node2 = node1.neighbors[j];

				if (node1.neighbors.length + node2.neighbors.length - 4 < ret) {
					for (k = 0; k < node2.neighbors.length; k++) {
						var node3 = node2.neighbors[k];
						if (node3.adjMap[node1.nodeIndex] != null)
							ret = Math.min(ret, node1.neighbors.length + node2.neighbors.length + node3.neighbors.length - 6);
					}
				}
			}
		}
	}

	return ret == Infinity ? -1 : ret;
}

function main() {
	var splitted = readline().split(' ');
	var n = parseInt(splitted[0]);
	var m = parseInt(splitted[1]);
	var nodes = new Array(n);
	var i;
	var u, v;
	var dummyObj = {};
	var adjMap = {};

	for (u = 0; u < n; u++) {
		nodes[u] = {nodeIndex: u, neighbors: [], adjMap: {}};
	}
	for (i = 0; i < m; i++) {
		splitted = readline().split(' ');
		u = parseInt(splitted[0]) - 1;
		v = parseInt(splitted[1]) - 1;
		if (u != v) {
			nodes[u].adjMap[v] = dummyObj;
			nodes[v].adjMap[u] = dummyObj;
			nodes[u].neighbors.push(nodes[v]);
			nodes[v].neighbors.push(nodes[u]);
		}
	}

	var answer = minimumSumOfRecogitions(nodes, adjMap);
	print(answer);
}

main();

/* TEST CASE
input
5 6
1 2
1 3
2 3
2 4
3 4
4 5
output
2

input
7 4
2 1
3 6
5 1
1 7
output
-1

*/
function minimumSumOfRecogitions(nodes, adjMap) {
	var ret = Infinity;
	var n = nodes.length;
	var i, j, k;
//	var sorter = function (v1, v2) {return v1.neighbors.length - v2.neighbors.length;};
//	for (i = 0; i < n; i++) {
//		nodes[i].neighbors.sort(sorter);
//	}
//	nodes.sort(sorter);

	for (i = 0; i < n; i++) {
		var node1 = nodes[i];
		if (node1.neighbors.length < ret) {
			for (j = 0; j < node1.neighbors.length; j++) {
				var node2 = node1.neighbors[j];

				if (node1.neighbors.length + node2.neighbors.length < ret) {
					for (k = 0; k < node2.neighbors.length; k++) {
						var node3 = node2.neighbors[k];
						if (node3.adjMap[node1.nodeIndex] != null)
							ret = Math.min(ret, node1.neighbors.length + node2.neighbors.length + node3.neighbors.length - 6);
					}
				}
			}
		}
	}

	return ret == Infinity ? -1 : ret;
}

function main() {
	var splitted = readline().split(' ');
	var n = parseInt(splitted[0]);
	var m = parseInt(splitted[1]);
	var nodes = new Array(n);
	var i;
	var u, v;
	var dummyObj = {};
	var adjMap = {};

	for (u = 0; u < n; u++) {
		nodes[u] = {nodeIndex: u, neighbors: [], adjMap: {}};
	}
	for (i = 0; i < m; i++) {
		splitted = readline().split(' ');
		u = parseInt(splitted[0]) - 1;
		v = parseInt(splitted[1]) - 1;
		if (u != v) {
			nodes[u].neighbors.push(nodes[v]);
			nodes[u].adjMap[v] = dummyObj;
			nodes[v].neighbors.push(nodes[u]);
			nodes[v].adjMap[u] = dummyObj;
		}
	}

	var answer = minimumSumOfRecogitions(nodes, adjMap);
	print(answer);
}

main();

/* TEST CASE
input
5 6
1 2
1 3
2 3
2 4
3 4
4 5
output
2

input
7 4
2 1
3 6
5 1
1 7
output
-1

*/
function minimumSumOfRecogitions(nodes, adjMap) {
	var n = nodes.length;
	var i, j, k;
	var sorter = function (v1, v2) {return v1.neighbors.length - v2.neighbors.length;};
	for (i = 0; i < n; i++) {
		nodes[i].neighbors.sort(sorter);
	}
	nodes.sort(sorter);

	for (i = 0; i < n; i++) {
		var node1 = nodes[i];
		for (j = 0; j < node1.neighbors.length; j++) {
			var node2 = node1.neighbors[j];

			for (k = 0; k < node2.neighbors.length; k++) {
				var node3 = node2.neighbors[k];
				if (adjMap[Math.min(node3.nodeIndex, node1.nodeIndex) + ":" + Math.max(node3.nodeIndex, node1.nodeIndex)] != null)
					return node1.neighbors.length + node2.neighbors.length + node3.neighbors.length - 6;
			}
		}
	}

	return -1;
}

function main() {
	var splitted = readline().split(' ');
	var n = parseInt(splitted[0]);
	var m = parseInt(splitted[1]);
	var nodes = new Array(n);
	var i;
	var u, v;
	var dummyObj = {};
	var adjMap = {};

	for (u = 0; u < n; u++) {
		nodes[u] = {nodeIndex: u, neighbors: []};
	}
	for (i = 0; i < m; i++) {
		splitted = readline().split(' ');
		u = parseInt(splitted[0]) - 1;
		v = parseInt(splitted[1]) - 1;
		if (u != v) {
			nodes[u].neighbors.push(nodes[v]);
			nodes[v].neighbors.push(nodes[u]);
			adjMap[Math.min(u, v) + ":" + Math.max(u, v)] = dummyObj;
		}
	}

	var answer = minimumSumOfRecogitions(nodes, adjMap);
	print(answer);
}

main();


'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}

main()

function main() {
  const inp = getInts()
  let s = getLine()[0]
  solve(s, ...inp)
}

function solve (s, k, a, b) {
  let n = s.length
  const dp = []
  for (let i = 0; i <= k; ++i) {
    dp.push([])
  }

  for (let i = 0; i <= k; ++i) {
    for (let j = 0; j <= n; ++j) {
      dp[i][j] = 0
    }
  }

  for (let i = a; i <= b; ++i) dp[1][i] = 1

  for (let i = 2; i <= k; ++i) {
    for (let j = i * a; j <= i * b && j <= n; ++j) {
      dp[i][j] = 1
    }
  }

  if (dp[k][n] === 0) print('No solution')
  else {
    const path = []
    for (let i = k; i > 1; --i) {
      for (let j = a; j <= b; ++j) {
        const val = n - j
        if (dp[i - 1][val]) {
          path.push(j)
          n -= j
          break
        }
      }
    }

    path.push(n)
    let ind = 0
    for (let i in path) {
      print(s.slice(ind, ind + path[i]))
      ind += path[i]
    }
  }
}

const readline = require('readline');

const rl = readline.createInterface({
  input: process.stdin,
  output: process.stdout
});

var isValid = function(s,pieces,len,minLen,maxLen){
    let sLen = s.length;
    let temp = sLen-len*(pieces-1);
    return temp>=minLen && temp<=maxLen;
}
var indicator=0,minLen,maxLen,pieces,temp=[];

rl.on('line', (input) => {
    if(indicator==0){
        temp = input.split(' ').map(item => parseInt(item));
        pieces = temp[0];
        minLen = temp[1];
        maxLen = temp[2];
        indicator++;
    }
    else{
        let i=minLen;
        for( ;i<=maxLen;i++)
            if(isValid(input,pieces,i,minLen,maxLen)) break;

        if(i==maxLen+1) console.log("No solution");
        else{
            /**
             * 0123456789..
             * abrakadabra
             */
            let startIndex=0;
            for(let j=0;j<pieces-1;j++){
            console.log(input.substr(startIndex,i));
            startIndex+=i;
            }
            console.log(input.substr(startIndex));
        }
        rl.close();
    }
  });

'use strict'

const getLine = () => readline().split(' ')
const getInts = () => getLine().map(n => parseInt(n))
const getInt = () => getInts()[0]
const D = (...args) => { // D({name})
  [...args].forEach(cur => print.apply(print, [JSON.stringify(cur)]))
}
const dp = {}

main()

function main() {
  const inp = getInts()
  let s = getLine()[0]
  const n = s.length

  const possible = solve(n, ...inp)
  if (!possible) print('No solution')
  else {
    let curN = n
    let curK = inp[0]
    let a = inp[1]
    const b = inp[2]
    while (a <= b) {
      const ok = solve(curN - a, curK - 1, a, b)
      if (ok) {
        print(s.slice(0, a))
        s = s.slice(a)
        curN -= a
        curK --
      }
      a ++
    }
  }
}

function solve (n, k, a, b) {
  if (n <= 0) {
    return n === 0 && k === 0
  }

  if (Object.hasOwnProperty(dp, [n, k])) return dp[[n, k]]

  let ans = 0
  for (let i = a; i <= b; ++i) {
    ans += solve(n - i, k - 1, a, b)
  }

  return dp[[n, k]] = ans
}


let y = '';
process.stdin.on('data', c => y += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = y.split(EOL);
	var t = lines[0];
	var n = 0;
	for(i = 1; i <= t * 2; i++){
	    if(i % 2 == 1){
	        n = lines[i];
	    }else{
	        var a = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});
	        var v = [];
	        var ans = '';
	        for(j = 1; j <= n; j++){
	            if(a[j] != a[j - 1]){
	                ans += a[j - 1] + ' ';
	            }else{
	                v.push(a[j - 1]);
	            }
	        }
	        for(j = 0; j < v.length; j++){
	            ans += v[j] + ' ';
	        }
	        console.log(ans);
	    }
	}
});

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
  const x = readline();
  //
  Array(parseInt(x)).fill(1).map((t, iii) => {
    var n = parseInt(readline())
    // var [n, m] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var ans = []
    var mark = new Array(n).fill(false)
    for (let j = 0; j < 103; j++) {
      for (let k = 0; k < 103; k++) {
        for (let i = 0; i < a.length; i++) {
          if (a[i] === k && !mark[i]) {
            ans.push(a[i])
            mark[i] = true
            break
          }
        }
      }
    }
    console.log(ans.join(' '))
  });

}

process.stdin.resume();
process.stdin.setEncoding("utf-8");

var standardInputString = "";
var currentLine = 0;

function readline() {
  return standardInputString[currentLine++];
}

process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});

process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function main() {
  let t = +readline();
  while (t--) {
    let n = +readline();
    let arr = readline()
      .split(" ")
      .map((val) => +val);
    let map = Array.from({ length: 101 }).fill(0);
    let ans = [];
    for (let i = 0; i < arr.length; ++i) {
      map[arr[i]]++;
    }
    for (let i = 0; i <= 100; ++i) {
      if (map[i] > 0) {
        ans.push(i);
        map[i]--;
      }
    }

    for (let i = 0; i <= 100; ++i) {
      for (let j = 0; j < map[i]; ++j) {
        ans.push(i);
      }
    }
    console.log(ans.join(" "));
  }
}

let input = '';
process.stdin.on('data', (c) => {
    input += c;
});

process.stdin.on('end', () => {
    const lines = input.split('\n');
    const cases = parseInt(lines[0]);

    let prevLetter;
    for (let i = 2; i < cases * 2 + 1; i += 2) {
        const line = lines[i];
        const numbers = line.split(' ').map(t => parseInt(t.trim()));

        const sorted = numbers.slice().sort((a, b) => a - b);

        const prev = [];
        const append = [];
        for (let j = 0; j < sorted.length; j++) {
            const num = sorted[j];
            if (!prev.includes(num)) {
                prev.push(num);
            } else {
                append.push(num);
            }
        }
        console.log([...prev, ...append].join(' '));
    }
});

process.stdin.setEncoding('utf-8')
const readline = require('readline')

const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    }
)

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data * 2
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve(n, arr) {
    arr.sort((a, b) => a - b)
    const res = [], res2 = []
    let temp = -1
    arr.forEach(i => {
        if (i !== temp) res.push(i)
        else res2.push(i)
        temp = i
    })
    console.log(res.join(' '), res2.join(' '))
}

function main() {
    for (let i = 0; i < inputArr.length; i += 2) solve(inputArr[i][0], inputArr[i + 1])
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray(N);
		list.sort(function(a,b){
			return a - b;
		});
		var output = [];
		var ato = [];
		var now = 0;
		for(var j = 0; j < N; j++){
			if(list[j] == now){
				output.push(list[j]);
				now++;
			}else{
				ato.push(list[j]);
			}
		}
		output = output.concat(ato);
		myout(myconv(output, 8));
	}
}

///////////////////////////////// pre-define /////////////////////////////////////
const pr = console.log;
///////////////////////////////////////////////////////////////////////////////////

const solve = (n, a) => {
    let m = new Map();
    for (const e of a) {
        m.set(e, m.get(e) + 1 || 1);
    }
    m = sortMapByKey(m);
    let res = Array.from(m.keys());
    for (const [k, v] of m) {
        if (v == 1) continue;
        for (let i = 1; i <= v - 1; i++) {
            res.push(k);
        }
    }
    pr(res.join(" "));
};

const sortMapByKey = (map) => {
    return new Map([...map].sort((a, b) => a[0] - b[0]));
};

const main = () => {
    const readline = require('readline');
    const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    });
    let input = [];
    rl.on('line', (line) => {
        input.push(line.split(" ").map(x => Number(x)));
    });
    rl.on('close', () => {
        let t = input[0][0];
        let i = 1;
        while (t--) {
            solve(input[i][0], input[i + 1]);
            i += 2;
        }
    });
};

main()

var t = parseInt(readline());
while (t--) {
    var mystring = "";
    var n = parseInt(readline());
    var arr = readline().split(" ").map(function(x) {return parseInt(x)});
    var count = new Array(110).fill(0);
    for (var i = Number(0); i < n; i++) {
        count[arr[i]]++;
    }
    for (var i = 0; i < 110; i++) {
        if (count[i] > 0) {
            mystring = mystring + i + " ";
            count[i]--;
        }
    }
    for (var i = 0; i < 110; i++) {
        while (count[i] > 0) {
            mystring = mystring + i + " ";
            count[i]--;
        }
    }
    print(mystring)
}

function getInt(num){
    return parseInt(num, 10)
}

var t = parseInt(readline(), 10);

for(var i = 0; i<t; i++){
    var n = getInt(readline());
    var innerLine = readline().split(' ').map(getInt);
    solution(innerLine);
}
function solution(arr){
    var counters = new Array(100);
    var res = [];

    arr.forEach(function(item){
        counters[item] = (counters[item] || 0) + 1;
    });
    if(!counters[0]){
        print(arr.join(' '))
        return;
    }

    counters.map(function(item, i){
        if(item){
            res.push(i);
            item--;
        }
        return item;
    }).forEach(function(item, i){
        for(var k = 0; k < (item || 0); k++){
            res.push(i);
        }
    })
    print(res.join(' '));
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
  const x = readline();
  //
  Array(parseInt(x)).fill(1).map((t, iii) => {
    var n = parseInt(readline())
    // var [n, m] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var ans = []
    var mark = new Array(n).fill(false)
    for (let j = 0; j < 102; j++) {
      for (let k = 0; k < 100; k++) {
        for (let i = 0; i < a.length; i++) {
          if (a[i] === k && !mark[i]) {
            ans.push(a[i])
            mark[i] = true
            break
          }
        }
      }
    }
    console.log(ans.join(' '))
  });

}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
  inputString += inputStdin;
});

process.stdin.on('end', _ => {
  inputString = inputString.trim().split('\n').map(string => {
    return string.trim();
  });

  main();
});

function readline() {
  return inputString[currentLine++];
}

// Make a Snippet for the code above this and then write your logic in main();
var mod = 1000000000n + 7n
var maxN = 1002

function main() {
  const x = readline();
  //
  Array(parseInt(x)).fill(1).map((t, iii) => {
    var n = parseInt(readline())
    // var [n, m] = readline().split(' ').map((x, iii) => {
    //   return parseInt(x)
    // });
    var a = readline().split(' ').map((x, iii) => {
      return parseInt(x)
    });
    var ans = []
    var mark = new Array(n).fill(false)
    for (let j = 0; j < 100; j++) {
      for (let k = 0; k < 100; k++) {
        for (let i = 0; i < a.length; i++) {
          if (a[i] === k && !mark[i]) {
            ans.push(a[i])
            mark[i] = true
            break
          }
        }
      }
    }
    console.log(ans.join(' '))
  });

}

process.stdin.resume();
process.stdin.setEncoding("utf-8");

var standardInputString = "";
var currentLine = 0;

function readline() {
  return standardInputString[currentLine++];
}

process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});

process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function main() {
  let t = +readline();
  while (t--) {
    let n = +readline();
    let arr = readline()
      .split(" ")
      .map((val) => +val);
    let map = Array.from({ length: 101 }).fill(0);
    let ans = [];
    for (let i = 0; i < arr.length; ++i) {
      map[arr[i]]++;
    }
    for (let i = 0; i <= 100; ++i) {
      if (map[i] > 0) {
        ans.push(i);
        map[i]--;
      }
    }

    for (let i = 0; i <= 100; ++i) {
      for (let j = 0; j < map[i]; ++j) {
        ans.push(i);
      }
    }
    console.log(ans);
  }
}

process.stdin.resume();
process.stdin.setEncoding("utf-8");

var standardInputString = "";
var currentLine = 0;

function readline() {
  return standardInputString[currentLine++];
}

process.stdin.on("data", (rawData) => {
  standardInputString += rawData;
});

process.stdin.on("end", (_) => {
  standardInputString = standardInputString
    .trim()
    .split("\n")
    .map((line) => {
      return line.trim();
    });
  main();
});

function main() {
  let t = +readline();
  while (t--) {
    let n = +readline();
    let arr = readline()
      .split(" ")
      .map((val) => +val);
    let count = {};
    for (let i = 0; i < arr.length; ++i) {
      if (count[arr[i]]) count[arr[i]]++;
      else {
        count[arr[i]] = 1;
      }
    }
    let ans = [];
    for (let i = 0; i < arr.length; ++i) {
      if (count[arr[i]] === 1) ans.push(arr[i]);
    }
    for (let i = 0; i < arr.length; ++i) {
      if (count[arr[i]] > 1) ans.push(arr[i]);
    }
    console.log(ans);
  }
}

let y = '';
process.stdin.on('data', c => y += c);
process.stdin.on('end', () => {
    const {EOL} = require('os');
    const lines = y.split(EOL);
	var t = lines[0];
	var e = 0;
    for(i = 1; i <= t * 2; i++){
        if(i % 2 == 1){
            e = lines[i] * 2;
        }else{
            var k = lines[i].split(' ').map(Number).sort(function(a, b){return a - b});
            var start = 0;
            var end = e - 1;
            var ans = '';
            while(start < end){
                ans += k[start] + ' ';
                start++;
                if(start > end){
                    break;
                }
                ans += k[end] + ' ';
                end--;
                if(start > end){
                    break;
                }
            }
            console.log(ans);
        }
    }
});

let input = '';
process.stdin.on('data', (c) => {
    input += c;
});

process.stdin.on('end', () => {
    const lines = input.split('\n');
    const cases = parseInt(lines[0]);

    let prevLetter;
    for (let i = 2; i < cases * 2 + 1; i += 2) {
        const line = lines[i];
        const numbers = line.split(' ').map(t => parseInt(t.trim()));

        const sorted = numbers.slice().sort((a, b) => a - b);

        let out = [];
        let prev = [];
        let append = [];
        let final = [];
        for (let j = 0; j < numbers.length; j++) {
            const num = numbers[j];
            if (!prev.includes(num)) {
                prev.push(num);
                out.push(num);
                out.sort((a, b) => a - b);
            } else {
              //  out.push(numbers[j + 1]);
                out.sort((a, b) => a - b);
                append = numbers.slice(j + 1);
                final.push(num);
                break;
            }
        }
        console.log([...out, ...append.sort((a, b) => a - b),  ...final.sort((a, b) => a - b)].join(' '));
    }
});

process.stdin.setEncoding('utf-8')
const readline = require('readline')

const rl = readline.createInterface({
        input: process.stdin,
        output: process.stdout
    }
)

let count = -1
let inputArr = []

rl.on('line', data => {
    if (count === -1) {
        count = +data * 2
    } else if (count !== 0) {
        inputArr.push(data.trim())
        count--
    }
    // max number 2^(53) - 1 ~~ 10^(15)
    if (count === 0) {
        inputArr = inputArr.map(i => i.split(' ').map(j => +j))
        main()
        process.exit(0)
    }
})

function solve(n, arr) {
    arr.sort((a, b) => a - b)
    const res = [], res2 = []
    let temp = -1
    arr.forEach(i => {
        if (i !== temp) res.push(i)
        else res2.push(i)
    })
    console.log(res.join(' '), res2.join(' '))
}

function main() {
    for (let i = 0; i < inputArr.length; i += 2) {
        solve(inputArr[i][0], inputArr[i + 1])
    }
}

//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	for(var i = 0; i < t; i++){
		var N = nextInt();
		var list = nextIntArray(N);
		list.sort(function(a,b){
			return a - b;
		});
		myout(myconv(list, 8));
	}
}


//Don't have to see. start------------------------------------------
var read = require('readline').createInterface({
	input: process.stdin, output: process.stdout
});
var obj; var inLine = []; var outputList = [];var retcode = new Set();
read.on('line', function(input){
	var tmp = input.split(' ');
	for(var i = 0; i < tmp.length; i++){
		inLine.push(tmp[i]);
		if(i == tmp.length - 1){
			retcode.add(inLine.length);
		}
	}
});
read.on('close', function(){
	obj = init(inLine);
	console.error('\n↑入力 ↓出力');
	Main();
	console.log(myconv(outputList, 9));
});
function makeClone(obj){return (obj instanceof Set) ? new Set(Array.from(obj)) : JSON.parse(JSON.stringify(obj));}
function nextArray(size, code){
	var ret = new Array(size);
	for(var i = 0; i < size; i++){
		if(code == 'int'){
			ret[i] = nextInt();
		}else if(code == 'long'){
			ret[i] = nextLong();
		}else if(code == 'double'){
			ret[i] = nextDouble();
		}else{
			ret[i] = next();
		}
	}
	return ret;
}
function nextIntArray(size){return nextArray(size, 'int');} function nextStrArray(size){return nextArray(size, 'str');} function nextLongArray(size){return nextArray(size, 'long');} function nextDoubleArray(size){return nextArray(size, 'double');}
function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();} function nextInt(){return myconv(next(),1);} function nextLong(){return BigInt(next());} function nextDouble(){return parseFloat(next());}
function getCountMap(list){
	var map = {};
	for(var i = 0; i < list.length; i++){
		if(map[list[i]] == null){
			map[list[i]] = 0;
		}
		map[list[i]]++;
	}
	return map;
}
function init(input){
	return {
		list : input, index : 0, max : input.length,
		hasNext : function(){return (this.index < this.max);},
		next : function(){if(this.hasNext()){return this.list[this.index++];}else{throw 'ArrayIndexOutOfBoundsException ‚There is no more input';}},
		isReturn : function(){return retcode.has(this.index);}
	};
}
function myout(s){outputList.push(s);}
function myerr(s){console.error('debug:' + require('util').inspect(s,false,null));}
function isReturn(){return obj.isReturn();}
//param "no" is
//unknown or outlier : return i. 1: parseInt.
//2: split space. 4: split space and parseInt.
//6: split 1 character. 7: split 1 character and parseInt.
//8: join space. 9: join nextline. 0: join no character.
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(' ');case 4:return i.split(' ').map(Number);case 6:return i.split('');case 7:return i.split('').map(Number);case 8:return i.join(' ');case 9:return i.join('\n');case 0:return i.join('');default:return i;}}catch(e){return i;}}

//Don't have to see. end------------------------------------------
function Main(){
	var t = nextInt();
	while(hasNext()){
		var N = nextInt();
		var list = new Array(N);
		for(var i = 0; i < N; i++){
			list[i] = nextCharArray();
		}
		var output = 0;
		for(var i = 0; i < N; i++){
			for(var j = 0; j < N; j++){
				var zero = 0;
				var one = 0;
				var x = i + 1;
				var y = j + 1;
				for(var k = 0; k < 4; k++){
					if(list[y - 1][x - 1] == "1"){
						one++;
					}else{
						zero++;
					}
					var tmp = x;
					x = y;
					y = N - tmp + 1;
				}
				output += Math.min(one, zero);
				for(var k = 0; k < 4; k++){
					list[y - 1][x - 1] = "1";
					var tmp = x;
					x = y;
					y = N - tmp + 1;
				}
			}
		}
		myout(output);
	}
}

var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        var n = parseInt(readline());
        var m = [];
        for (var i =0; i < n; i++) {
            m.push(readline().split('').map(x=>parseInt(x)));
        }
        var mid = Math.floor((n+1)/2);
        var ans = 0;
        for (var r = 0; r < mid; r++) {
            if (n & 1 && r == mid-1) {
                continue;
            }
            for (var c = 0; c < mid; c++) {
                var sum = m[r][c] + m[c][n-r-1] + m[n-c-1][r] + m[n-r-1][n-c-1];
                ans += Math.min(sum, 4-sum);

            }
        }
        print(ans);
    }

//Setup
let i = ''
let input;
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
  //console.log(lines);
  input=lines
//Actual Code

    //Input Reading and var config
    var numTests = parseInt(input[0])
    var testCases = []
    var indexReading=1
    while(indexReading<parseInt(input.length)){

        var size = parseInt(input[indexReading])
        var matrix = []
        for(b=0;b<size;b++){
            indexReading++
            matrix.push(input[indexReading].split(""))
        }
        indexReading++
       testCases.push({size:size,matrix:matrix})
    }
    testCases.pop()

    for(c=0;c<testCases.length;c++){
        var caseTesting = testCases[c]
        var ans = 0
        if(caseTesting.size==1){
            ans = 0
        }else{
            var ringsToTest = Math.floor(caseTesting.size/2)

            for(ring=0;ring<ringsToTest;ring++){
                arraysToCompare = [[],[],[],[]]

            for(index=0;index<caseTesting.size-1-(ring*2);index++){
                arraysToCompare[0].push(caseTesting.matrix[ring+index][ring])
                arraysToCompare[1].push(caseTesting.matrix[caseTesting.size-ring-1][ring+index])
                arraysToCompare[2].push(caseTesting.matrix[caseTesting.size-(1+ring+index)][caseTesting.size-(1+ring)])
                arraysToCompare[3].push(caseTesting.matrix[ring][caseTesting.size-(1+ring+index)])
               }
         //Array Comparing
            for(indexChecking=0;indexChecking<caseTesting.size-1-(ring*2);indexChecking++){
                var arrayChecking = [
                    arraysToCompare[0][indexChecking],
                    arraysToCompare[1][indexChecking],
                    arraysToCompare[2][indexChecking],
                    arraysToCompare[3][indexChecking]
                ]
            function numReps(array, element) {
                var reps = 0;
                array.forEach((valor) => (valor === element && reps++));
                return reps;
            }
            if(numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==2 ||
            numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==-2
            ){
                ans+=1
            }
            if(numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==0){
                ans+=2
            }
         }

        }
        }

        console.log(ans)

    }

})

const readline = require('readline')

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
})
const lines = []
rl.on('line', (input) => {
    lines.push(input);
})
rl.on('close', () => {
// (function() {
    // const lines = require('fs').readFileSync('test.in', 'utf8').split('\n')
    let l = 0;
    let t = +lines[l++]
    const output = []
    for (let i = 0; i < t; i++) {
        const n = +lines[l++]
        const arr = lines.slice(l, l + n).map(str => str.trim())
        l += n
        output[i] = solve(n, arr)
    }
    console.log(output.join('\n'))
// })()
})

function solve(n, arr) {
    let ans = 0
    const limit = Math.ceil(n / 2)
    for (let i = 0; i < limit; i++) {
        const t1 = []
        const t2 = []
        const t3 = []
        const t4 = []
        for (let j = 0; j < n - 1 - i * 2; j++) {
            // t1.push(arr[i][i + j])
            // t2.push(arr[i + j][n - 1 - i])
            // t3.push(arr[n - 1 - i][n - 1 - i - j])
            // t4.push(arr[n - 1 - i - j][i])
            const temp = [
                arr[i][i + j],
                arr[i + j][n - 1 - i],
                arr[n - 1 - i][n - 1 - i - j],
                arr[n - 1 - i - j][i]
            ]
            ans += cal(temp)
        }
            // console.log(t1, t2, t3, t4)
    }
    return ans
}
function cal(temp) {
    // console.log(temp)
    let c0 = 0, c1 = 0
    temp.forEach(x => {
        if (x === '0') c0++
        if (x === '1') c1++
    })
    return Math.min(c0, c1)
}

'use strict';

process.stdin.resume();
process.stdin.setEncoding('utf-8');

let inputString = '';
let currentLine = 0;

process.stdin.on('data', inputStdin => {
    inputString += inputStdin;
});

process.stdin.on('end', _ => {
    inputString = inputString.trim().split('\n').map(string => {
        return string.trim();
    });

    main();
});

function readline() {
    return inputString[currentLine++];
}

function output(x) {
    if (typeof x !== 'string') {
        x = x.toString();
    }
    //process.stdout.write(x);   // without auto '\n' (newline)
    console.log(x);  // with auto '\n' (newline)
}

function main() {
    let N = readline();

    for (let test = 0; test < N; test++) {
        let n = readline();
        let grid = [];
        for (let i = 0; i < n; i++) {
            grid[i] = readline().split('').map(Number);
        }

        let endLeft = Math.floor(n / 2);
        let endTop = Math.ceil(n / 2);

        const getAllSym = (row, col, n) => {
            // ROW, COLUMN
            return [
                [row, col],
                [col, n - row - 1],
                [n - row - 1, n - col - 1],
                [n - col - 1, row]
            ];
        }

        let steps = sum => {
            if (sum === 0 || sum === 4) {
                return 0;
            } else if (sum === 1 || sum === 3) {
                return 1;
            } else {
                return 2;
            }
        };

        let sumAllSym = (points, grid) => {
            return grid[points[0][0]][points[0][1]]
                + grid[points[1][0]][points[1][1]]
                + grid[points[2][0]][points[2][1]]
                + grid[points[3][0]][points[3][1]];
        };

        let res = 0;
        for (let left = 0; left < endLeft; left++) {
            for (let top = 0; top < endTop; top++) {
                let allSym = getAllSym(left, top, n);
                let sum = sumAllSym(allSym, grid);
                res += steps(sum);
            }
        }

        output(res);
    }
}

var t = parseInt(readline());

var rotatedCoord = function (coord, n) {
    return [coord[1], n - 1 - coord[0]];
}

for (var k = 0; k < t; k++) {
    var n = parseInt(readline());
    var matr = [];
    var ans = 0;

    for (var p = 0; p < n; p++) {
        var str = readline();
        matr.push(str);
    }

    if (n === 1) {
        print(0);
        continue;
    }

    for (var i = 0; i < (n-1)/2; i++) {
        for (var j = 0; j < n/2; j++) {
            var coord90 = rotatedCoord([i, j], n);
            var coord180 = rotatedCoord(coord90, n);
            var coord270 = rotatedCoord(coord180, n);

            var kit = [
                matr[i][j],
                matr[coord90[0]][coord90[1]],
                matr[coord180[0]][coord180[1]],
                matr[coord270[0]][coord270[1]]
            ];

            var count0 = 0;
            var count1 = 0;
            kit.forEach(item => {
                if (item === '0') {
                    count0++;
                } else {
                    count1++;
                }
            })

            ans += Math.min(count0, count1);
        }
    }

    print(ans);
}

//Setup
let i = ''
let input;
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
  //console.log(lines);
  input=lines
//Actual Code

    //Input Reading and var config
    var numTests = parseInt(input[0])
    var testCases = []
    var indexReading=1
    while(indexReading<parseInt(input.length)){

        var size = parseInt(input[indexReading])
        var matrix = []
        for(b=0;b<size;b++){
            indexReading++
            matrix.push(input[indexReading].split(""))
        }
        indexReading++
       testCases.push({size:size,matrix:matrix})
    }
    testCases.length==numTests

    for(c=0;c<testCases.length;c++){
        var caseTesting = testCases[c]
        var ans = 0
        if(caseTesting.size==1){
            ans = 0
        }else{
            var ringsToTest = Math.floor(caseTesting.size/2)

            for(ring=0;ring<ringsToTest;ring++){
                arraysToCompare = [[],[],[],[]]

            for(index=0;index<caseTesting.size-1-(ring*2);index++){
                arraysToCompare[0].push(caseTesting.matrix[ring+index][ring])
                arraysToCompare[1].push(caseTesting.matrix[caseTesting.size-ring-1][ring+index])
                arraysToCompare[2].push(caseTesting.matrix[caseTesting.size-(1+ring+index)][caseTesting.size-(1+ring)])
                arraysToCompare[3].push(caseTesting.matrix[ring][caseTesting.size-(1+ring+index)])
               }
         //Array Comparing
            for(indexChecking=0;indexChecking<caseTesting.size-1-(ring*2);indexChecking++){
                var arrayChecking = [
                    arraysToCompare[0][indexChecking],
                    arraysToCompare[1][indexChecking],
                    arraysToCompare[2][indexChecking],
                    arraysToCompare[3][indexChecking]
                ]
            function numReps(array, element) {
                var reps = 0;
                array.forEach((valor) => (valor === element && reps++));
                return reps;
            }
            if(numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==2 ||
            numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==-2
            ){
                ans+=1
            }
            if(numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==0){
                ans+=2
            }
         }

        }
        }

        console.log(ans)

    }

})

//Setup
let i = ''
let input;
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
  //console.log(lines);
  input=lines
//Actual Code

    //Input Reading and var config
    var numTests = parseInt(input[0])
    var testCases = []
    var indexReading=1
    while(indexReading<parseInt(input.length)){

        var size = parseInt(input[indexReading])
        var matrix = []
        for(b=0;b<size;b++){
            indexReading++
            matrix.push(input[indexReading].split(""))
        }
        indexReading++
       testCases.push({size:size,matrix:matrix})
    }
    console.log(testCases)
    for(c=0;c<testCases.length;c++){
        var caseTesting = testCases[c]
        var ans = 0
        if(caseTesting.size==1){
            ans = 0
        }else{
            var ringsToTest = Math.floor(caseTesting.size/2)

            for(ring=0;ring<ringsToTest;ring++){
                arraysToCompare = [[],[],[],[]]

            for(index=0;index<caseTesting.size-1-(ring*2);index++){
                arraysToCompare[0].push(caseTesting.matrix[ring+index][ring])
                arraysToCompare[1].push(caseTesting.matrix[caseTesting.size-ring-1][ring+index])
                arraysToCompare[2].push(caseTesting.matrix[caseTesting.size-(1+ring+index)][caseTesting.size-(1+ring)])
                arraysToCompare[3].push(caseTesting.matrix[ring][caseTesting.size-(1+ring+index)])
               }
         //Array Comparing
            for(indexChecking=0;indexChecking<caseTesting.size-1-(ring*2);indexChecking++){
                var arrayChecking = [
                    arraysToCompare[0][indexChecking],
                    arraysToCompare[1][indexChecking],
                    arraysToCompare[2][indexChecking],
                    arraysToCompare[3][indexChecking]
                ]
            function numReps(array, element) {
                var reps = 0;
                array.forEach((valor) => (valor === element && reps++));
                return reps;
            }
            if(numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==2 ||
            numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==-2
            ){
                ans+=1
            }
            if(numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==0){
                ans+=2
            }
         }

        }
        }

        console.log(ans)

    }

})

//Setup
let i = ''
let input;
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
  //console.log(lines);
  input=lines
//Actual Code

    //Input Reading and var config
    var numTests = parseInt(input[0])
    var testCases = []
    var indexReading=1
    while(indexReading<parseInt(input.length)){

        var size = parseInt(input[indexReading])
        var matrix = []
        for(c=0;c<size;c++){
            indexReading++
            matrix.push(input[indexReading].split(""))
        }
        indexReading++
       testCases.push({size:size,matrix:matrix})
    }
    console.log(testCases)
    for(c=0;c<testCases.length;c++){
        var caseTesting = testCases[c]
        var ans = 0
        if(caseTesting.size==1){
            ans = 0
        }else{
            var ringsToTest = Math.floor(caseTesting.size/2)

            for(ring=0;ring<ringsToTest;ring++){
                arraysToCompare = [[],[],[],[]]

            for(index=0;index<caseTesting.size-1-(ring*2);index++){
                arraysToCompare[0].push(caseTesting.matrix[ring+index][ring])
                arraysToCompare[1].push(caseTesting.matrix[caseTesting.size-ring-1][ring+index])
                arraysToCompare[2].push(caseTesting.matrix[caseTesting.size-(1+ring+index)][caseTesting.size-(1+ring)])
                arraysToCompare[3].push(caseTesting.matrix[ring][caseTesting.size-(1+ring+index)])
               }
         //Array Comparing
            for(indexChecking=0;indexChecking<caseTesting.size-1-(ring*2);indexChecking++){
                var arrayChecking = [
                    arraysToCompare[0][indexChecking],
                    arraysToCompare[1][indexChecking],
                    arraysToCompare[2][indexChecking],
                    arraysToCompare[3][indexChecking]
                ]
            function numReps(array, element) {
                var reps = 0;
                array.forEach((valor) => (valor === element && reps++));
                return reps;
            }
            if(numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==2 ||
            numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==-2
            ){
                ans+=1
            }
            if(numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==0){
                ans+=2
            }
         }

        }
        }

        console.log(ans)

    }

})

//Setup
let i = ''
let input;
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
  //console.log(lines);
  input=lines
//Actual Code
//Actual Code

    //Input Reading and var config
    var numTests = parseInt(input[0])
    var testCases = []
    var indexReading=1
    while(indexReading<parseInt(input.length)){

        var size = parseInt(input[indexReading])
        var matrix = []
        for(c=0;c<size;c++){
            indexReading++
            matrix.push(input[indexReading].split(""))
        }
        indexReading++
       testCases.push({size:size,matrix:matrix})
    }

    for(c=0;c<testCases.length;c++){
        var caseTesting = testCases[c]
        var ans = 0
        if(caseTesting.size==1){
            ans = 0
        }else{
            var ringsToTest = Math.floor(caseTesting.size/2)

            for(ring=0;ring<ringsToTest;ring++){
                arraysToCompare = [[],[],[],[]]

            for(index=0;index<caseTesting.size-1-(ring*2);index++){
                arraysToCompare[0].push(caseTesting.matrix[ring+index][ring])
                arraysToCompare[1].push(caseTesting.matrix[caseTesting.size-ring-1][ring+index])
                arraysToCompare[2].push(caseTesting.matrix[caseTesting.size-(1+ring+index)][caseTesting.size-(1+ring)])
                arraysToCompare[3].push(caseTesting.matrix[ring][caseTesting.size-(1+ring+index)])
               }
         //Array Comparing
            for(indexChecking=0;indexChecking<caseTesting.size-1-(ring*2);indexChecking++){
                var arrayChecking = [
                    arraysToCompare[0][indexChecking],
                    arraysToCompare[1][indexChecking],
                    arraysToCompare[2][indexChecking],
                    arraysToCompare[3][indexChecking]
                ]
            function numReps(array, element) {
                var reps = 0;
                array.forEach((valor) => (valor === element && reps++));
                return reps;
            }
            if(numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==2 ||
            numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==-2
            ){
                ans+=1
            }
            if(numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==0){
                ans+=2
            }
         }

        }
        }

        console.log(ans)

    }

})

//Setup
let i = ''
let input;
process.stdin.on('data', c => i += c)
process.stdin.on('end', () => {
    const {EOL} = require('os')
    const lines = i.split(EOL) /*your input text, split by lines*/
  //console.log(lines);
  input=lines
//Actual Code

    //Input Reading and var config
    var numTests = parseInt(input[0])
    var testCases = []
    var indexReading=1
    while(indexReading<parseInt(input.length)){

        var size = parseInt(input[indexReading])
        var matrix = []
        for(c=0;c<size;c++){
            indexReading++
            matrix.push(input[indexReading].split(""))
        }
        indexReading++
       testCases.push({size:size,matrix:matrix})
    }

    for(c=0;c<testCases.length;c++){
        var caseTesting = testCases[c]
        var ans = 0
        if(caseTesting.size==1){
            ans = 0
        }else{
            var ringsToTest = Math.floor(caseTesting.size/2)

            for(ring=0;ring<ringsToTest;ring++){
                arraysToCompare = [[],[],[],[]]

            for(index=0;index<caseTesting.size-1-(ring*2);index++){
                arraysToCompare[0].push(caseTesting.matrix[ring+index][ring])
                arraysToCompare[1].push(caseTesting.matrix[caseTesting.size-ring-1][ring+index])
                arraysToCompare[2].push(caseTesting.matrix[caseTesting.size-(1+ring+index)][caseTesting.size-(1+ring)])
                arraysToCompare[3].push(caseTesting.matrix[ring][caseTesting.size-(1+ring+index)])
               }
         //Array Comparing
            for(indexChecking=0;indexChecking<caseTesting.size-1-(ring*2);indexChecking++){
                var arrayChecking = [
                    arraysToCompare[0][indexChecking],
                    arraysToCompare[1][indexChecking],
                    arraysToCompare[2][indexChecking],
                    arraysToCompare[3][indexChecking]
                ]
            function numReps(array, element) {
                var reps = 0;
                array.forEach((valor) => (valor === element && reps++));
                return reps;
            }
            if(numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==2 ||
            numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==-2
            ){
                ans+=1
            }
            if(numReps(arrayChecking,"0")-numReps(arrayChecking,"1")==0){
                ans+=2
            }
         }

        }
        }

        console.log(ans)

    }
})

var t = parseInt(readline());

var rotatedCoord = function (coord, n) {
    return [coord[1], n - 1 - coord[0]];
}

for (var k = 0; k < t; k++) {
    var n = parseInt(readline());
    var matr = [];
    var ans = 0;

    for (var p = 0; p < n; p++) {
        var str = readline();
        matr.push(str.split(' '));
    }

    if (n === 1) {
        print(0);
        continue;
    }

    for (var i = 0; i < (n-1)/2; i++) {
        for (var j = 0; j < n/2; j++) {
            var coord90 = rotatedCoord([i, j], n);
            var coord180 = rotatedCoord(coord90, n);
            var coord270 = rotatedCoord(coord180, n);

            var kit = [
                matr[i][j],
                matr[coord90[0]][coord90[1]],
                matr[coord180[0]][coord180[1]],
                matr[coord270[0]][coord270[1]]
            ];

            var count0 = 0;
            var count1 = 0;
            kit.forEach(item => {
                parseInt(item) === 0 && count0++;
                parseInt(item) === 1 && count1++;
            })

            ans += Math.min(count0, count1);
        }
    }

    print(ans);
}

var t = parseInt(readline());

var rotatedCoord = function (coord, n) {
    return [coord[1], n - 1 - coord[0]];
}

for (var k = 0; k < t; k++) {
    var n = parseInt(readline());
    var matr = [];
    var ans = 0;

    for (var p = 0; p < n; p++) {
        var str = readline();
        matr.push(str);
    }
    print(matr);

    if (n === 1) {
        print(0);
        continue;
    }

    for (var i = 0; i < n/2; i++) {
        for (var j = 0; j < n/2 + n%2; j++) {
            var coord90 = rotatedCoord([i, j], n);
            var coord180 = rotatedCoord(coord90, n);
            var coord270 = rotatedCoord(coord180, n);

            var kit = [
                matr[i][j],
                matr[coord90[0]][coord90[1]],
                matr[coord180[0]][coord180[1]],
                matr[coord270[0]][coord270[1]]
            ];

            print(kit);

            var count0 = 0;
            var count1 = 0;
            kit.forEach(item => {
                if (item === '0') {
                    count0++;
                } else {
                    count1++;
                }
            })

            ans += Math.min(count0, count1);
        }
    }

    print(ans);
}

var t = parseInt(readline());

var rotatedCoord = function (coord, n) {
    return [coord[1], n - 1 - coord[0]];
}

for (var k = 0; k < t; k++) {
    var n = parseInt(readline());
    var matr = [];
    var ans = 0;

    for (var p = 0; p < n; p++) {
        var str = readline();
        matr.push(str.split(''));
    }

    if (n === 1) {
        print(0);
        continue;
    }

    for (var i = 0; i < n/2; i++) {
        for (var j = 0; j < n/2 + n%2; j++) {
            var coord90 = rotatedCoord([i, j], n);
            var coord180 = rotatedCoord(coord90, n);
            var coord270 = rotatedCoord(coord180, n);

            var kit = [
                matr[i][j],
                matr[coord90[0]][coord90[1]],
                matr[coord180[0]][coord180[1]],
                matr[coord270[0]][coord270[1]]
            ];

            var kitSum = kit.reduce((sum, elem) => sum + parseInt(elem), 0);

            ans += Math.min(kitSum, 4 - kitSum);
        }
    }

    print(ans);
}

var t = parseInt(readline());

var rotatedCoord = function (coord, n) {
    return [coord[1], n - 1 - coord[0]];
}

for (var k = 0; k < t; k++) {
    var n = parseInt(readline());
    var matr = [];
    var ans = 0;

    for (var p = 0; p < n; p++) {
        var str = readline();
        matr.push(str);
    }

    if (n === 1) {
        print(0);
        continue;
    }

    for (var i = 0; i < n/2; i++) {
        for (var j = 0; j < n/2 + n%2; j++) {
            var coord90 = rotatedCoord([i, j], n);
            var coord180 = rotatedCoord(coord90, n);
            var coord270 = rotatedCoord(coord180, n);

            var kit = [
                matr[i][j],
                matr[coord90[0]][coord90[1]],
                matr[coord180[0]][coord180[1]],
                matr[coord270[0]][coord270[1]]
            ];

            var count0 = 0;
            var count1 = 0;
            kit.forEach(item => {
                if (item === '0') {
                    count0++;
                } else {
                    count1++;
                }
            })

            ans += Math.min(count0, count1);
        }
    }

    print(ans);
}

var t = parseInt(readline());

var rotatedCoord = function (coord, n) {
    return [coord[1], n - 1 - coord[0]];
}

for (var k = 0; k < t; k++) {
    var n = parseInt(readline());
    var matr = [];
    var ans = 0;

    for (var p = 0; p < n; p++) {
        var str = readline();
        matr.push(str.split(''));
    }

    if (n === 1) {
        print(0);
        continue;
    }

    for (var i = 0; i < n/2; i++) {
        for (var j = 0; j < n/2 + n%2; j++) {
            var coord90 = rotatedCoord([i, j], n);
            var coord180 = rotatedCoord(coord90, n);
            var coord270 = rotatedCoord(coord180, n);

            var kit = [
                matr[i][j],
                matr[coord90[0]][coord90[1]],
                matr[coord180[0]][coord180[1]],
                matr[coord270[0]][coord270[1]]
            ];

            var kitSum = kit.reduce((sum, elem) => sum + parseInt(elem), 0);

            ans += Math.min(kitSum, n - kitSum);
        }
    }

    print(ans);
}

var t = parseInt(readline());

var rotatedCoord = function (coord, n) {
    return [coord[1], n - 1 - coord[0]];
}

for (var k = 0; k < t; k++) {
    var n = parseInt(readline());
    var matr = [];
    var ans = 0;

    for (var p = 0; p < n; p++) {
        var str = readline();
        matr.push(str.split(' '));
    }

    if (n === 1) {
        print(0);
        continue;
    }

    for (var i = 0; i < n/2 + n%2; i++) {
        for (var j = 0; j < n/2 + n%2; j++) {
            var coord90 = rotatedCoord([i, j], n);
            var coord180 = rotatedCoord(coord90, n);
            var coord270 = rotatedCoord(coord180, n);

            var kit = [
                matr[i][j],
                matr[coord90[0]][coord90[1]],
                matr[coord180[0]][coord180[1]],
                matr[coord270[0]][coord270[1]]
            ];

            var count0 = 0;
            var count1 = 0;
            kit.forEach(item => {
                parseInt(item) === 0 && count0++;
                parseInt(item) === 1 && count1++;
            })

            ans += Math.min(count0, count1);
        }
    }

    print(ans);
}

var t = parseInt(readline());

var rotatedCoord = function (coord, n) {
    return [coord[1], n - 1 - coord[0]];
}

for (var k = 0; k < t; k++) {
    var n = parseInt(readline());
    var matr = [];
    var ans = 0;

    for (var p = 0; p < n; p++) {
        var str = readline();
        matr.push(str.split(' '));
    }

    if (n === 1) {
        print(0);
        continue;
    }

    for (var i = 0; i < n/2; i++) {
        for (var j = 0; j < n/2 + n%2; j++) {
            var coord90 = rotatedCoord([i, j], n);
            var coord180 = rotatedCoord(coord90, n);
            var coord270 = rotatedCoord(coord180, n);

            var kit = [
                matr[i][j],
                matr[coord90[0]][coord90[1]],
                matr[coord180[0]][coord180[1]],
                matr[coord270[0]][coord270[1]]
            ];

            var count0 = 0;
            var count1 = 0;
            kit.forEach(item => {
                parseInt(item) === 0 && count0++;
                parseInt(item) === 1 && count1++;
            })

            ans += Math.min(count0, count1);
        }
    }

    print(ans);
}

var t = parseInt(readline());

var rotatedCoord = function (coord, n) {
    return [coord[1], n - 1 - coord[0]];
}

for (var k = 0; k < t; k++) {
    var n = parseInt(readline());
    var matr = [];
    var ans = 0;

    for (var p = 0; p < n; p++) {
        var str = readline();
        matr.push(str.split(' '));
    }

    if (n === 1) {
        print(0);
        continue;
    }

    for (var i = 0; i < n/2; i++) {
        for (var j = 0; j < n/2 + n%2; j++) {
            var coord90 = rotatedCoord([i, j], n);
            var coord180 = rotatedCoord(coord90, n);
            var coord270 = rotatedCoord(coord180, n);

            var kit = [
                matr[i][j],
                matr[coord90[0]][coord90[1]],
                matr[coord180[0]][coord180[1]],
                matr[coord270[0]][coord270[1]]
            ];

            var count0 = 0;
            var count1 = 0;
            kit.forEach(item => {
                if (item == 0) {
                    count0++;
                } else {
                    count1++;
                }
            })

            ans += Math.min(count0, count1);
        }
    }

    print(ans);
}

var t = parseInt(readline());

var rotatedCoord = function (coord, n) {
    return [coord[1], n - 1 - coord[0]];
}

for (var k = 0; k < t; k++) {
    var n = parseInt(readline());
    var matr = [];
    var ans = 0;

    for (var p = 0; p < n; p++) {
        var str = readline();
        matr.push(str.split(' '));
    }

    if (n === 1) {
        print(0);
        continue;
    }

    for (var i = 0; i < n/2; i++) {
        for (var j = 0; j < n/2 + n%2; j++) {
            var coord90 = rotatedCoord([i, j], n);
            var coord180 = rotatedCoord(coord90, n);
            var coord270 = rotatedCoord(coord180, n);

            var kit = [
                matr[i][j],
                matr[coord90[0]][coord90[1]],
                matr[coord180[0]][coord180[1]],
                matr[coord270[0]][coord270[1]]
            ];

            var count0 = 0;
            var count1 = 0;
            kit.forEach(item => {
                if (parseInt(item) === 0) {
                    count0++;
                } else {
                    count1++;
                }
            })

            ans += Math.min(count0, count1);
        }
    }

    print(ans);
}

var t = parseInt(readline());

var rotatedCoord = function (coord, n) {
    return [coord[1], n - 1 - coord[0]];
}

for (var k = 0; k < t; k++) {
    var n = parseInt(readline());
    var matr = [];
    var ans = 0;

    for (var p = 0; p < n; p++) {
        var str = readline();
        matr.push(str.split(' '));
    }

    if (n === 1) {
        print(0);
        continue;
    }

    for (var i = 0; i < n/2; i++) {
        for (var j = 0; j < n/2 + n%2; j++) {
            var coord90 = rotatedCoord([i, j], n);
            var coord180 = rotatedCoord(coord90, n);
            var coord270 = rotatedCoord(coord180, n);

            var kit = [
                matr[i][j],
                matr[coord90[0]][coord90[1]],
                matr[coord180[0]][coord180[1]],
                matr[coord270[0]][coord270[1]]
            ];

            var count0 = 0;
            var count1 = 0;

            for (var p = 0; p < kit.length; p++) {
                if (parseInt(kit[p]) === 0) {
                    count0++;
                } else {
                    count1++;
                }
            }

            ans += Math.min(count0, count1);
        }
    }

    print(ans);
}

var t = parseInt(readline());

var rotatedCoord = function (coord, n) {
    return [coord[1], n - 1 - coord[0]];
}

for (var k = 0; k < t; k++) {
    var n = parseInt(readline());
    var matr = [];
    var ans = 0;

    for (var p = 0; p < n; p++) {
        var str = readline();
        matr.push(str.split(' '));
    }

    if (n === 1) {
        print(0);
        continue;
    }

    for (var i = 0; i < n/2; i++) {
        for (var j = 0; j < n/2 + n%2; j++) {
            var coord90 = rotatedCoord([i, j], n);
            var coord180 = rotatedCoord(coord90, n);
            var coord270 = rotatedCoord(coord180, n);

            var kit = [
                matr[i][j],
                matr[coord90[0]][coord90[1]],
                matr[coord180[0]][coord180[1]],
                matr[coord270[0]][coord270[1]]
            ];

            var count0 = 0;
            var count1 = 0;
            kit.forEach(item => {
                if (item === '0') {
                    count0++;
                } else {
                    count1++;
                }
            })

            ans += Math.min(count0, count1);
        }
    }

    print(ans);
}

var t = parseInt(readline());

var rotatedCoord = function (coord, n) {
    return [coord[1], n - 1 - coord[0]];
}

for (var k = 0; k < t; k++) {
    var n = parseInt(readline());
    var matr = [];
    var ans = 0;

    for (var p = 0; p < n; p++) {
        var str = readline();
        matr.push(str.split(' '));
    }

    if (n === 1) {
        print(0);
        continue;
    }

    for (var i = 0; i < n/2; i++) {
        for (var j = 0; j < n/2 + n%2; j++) {
            var coord90 = rotatedCoord([i, j], n);
            var coord180 = rotatedCoord(coord90, n);
            var coord270 = rotatedCoord(coord180, n);

            var kit = [
                matr[i][j],
                matr[coord90[0]][coord90[1]],
                matr[coord180[0]][coord180[1]],
                matr[coord270[0]][coord270[1]]
            ];

            var count0 = 0;
            var count1 = 0;
            kit.forEach(item => {
                if (item === 0) {
                    count0++;
                } else {
                    count1++;
                }
            })

            ans += Math.min(count0, count1);
        }
    }

    print(ans);
}

var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        var n = parseInt(readline());
        var m = [];
        for (var i =0; i < n; i++) {
            m.push(readline().split('').map(x=>parseInt(x)));
        }
        var mid = (n+1)/2;
        var ans = 0;
        for (var r = 0; r < mid; r++) {
            if (n & 1 && r == mid-1) {
                continue;
            }
            for (var c = 0; c < mid; c++) {
                var sum = m[r][c] + m[c][n-r-1] + m[n-c-1][r] + m[n-r-1][n-c-1];
                ans += Math.min(sum, 4-sum);

            }
        }
        print(ans);
    }

var tests = parseInt(readline());
    for (var t=0; t<tests;t++) {
        var n = parseInt(readline());
        var m = [];
        for (var i =0; i < n; i++) {
            m.push(readline().split('').map(x=>parseInt(x)));
        }
        var mid = (n+1)/2;
        var ans = 0;
        for (var r = 0; r < mid; r++) {
            for (var c = 0; c < mid; c++) {
                if (n & 1 && r == mid-1) {
                    continue;
                }
                var sum = m[r][c] + m[c][n-r-1] + m[n-c-1][r] + m[n-r-1][n-c-1];
                ans += Math.min(sum, 4-sum);

            }
        }
        print(ans);
    }


function sortNumber(a,b) {
    return a - b;
}

    function sa(){
        var firstLine =readline().split(" ");
        var n1 = Math.min(Number(firstLine[1]), Number(firstLine[2]));
        var n2 = Math.max(Number(firstLine[1]), Number(firstLine[2]));
        var n = Number(firstLine[1]) + Number(firstLine[2]);
        var data = readline().split(" ").map(Number);
        data.sort(sortNumber).reverse();
        var sum = 0;
        var sum1 = 0;
        var sum2 = 0;
        for(var i=0;i<n;i++){
            if(i<n1){
                sum1 += data[i];
            } else {
                sum2 += data[i];
            }
        }

        print(sum1/n1 + sum2/n2)
    }
    sa();

"use strict";

/*
let kk = 0;
let readline = function() {
	switch(kk++) {
		case 0: return '4 2 1';
		case 1: return '1 4 2 3';
	}
};
let write = console.log.bind();
*/

Array.prototype.sum = function(arr) {
	let s = 0;
	for ( let i = 0; i < this.length; i++ )
		s += this[i];

	return s;
};

let input = readline().split(' ').map(e => +e),
	n = input[0],
	n1 = input[1],
	n2 = input[2],
	A = readline().split(' ').map(e => +e).sort((a, b) => a - b),
	min = Math.min(n1, n2),
	max = n1 === min ? n2 : n1;

let opti = A.splice(-min).sum()/min;
opti += A.splice(-max).sum()/max;
write(opti.toFixed(6))

var mainFunc = function(arr, amount1, amount2)
	{
		var sum = function(arr, amount)
		{
			var sumIn = 0;
			for (var i = 0; i <= amount - 1; i++)
			{
				sumIn += arr[i];
			}
			sumIn /= amount;
			return sumIn;
		}
		arr = arr.slice(0, amount1 + amount2 + 1);
		if (amount1 < amount2)
			{
				var sumAmount1 = sum(arr, amount1);
				arr = arr.slice(amount1, arr.length);
				var sumAmount2 = sum(arr, amount2);
				return sumAmount1 + sumAmount2;
			}
		else
			{
				var sumAmount1 = sum(arr, amount2);
				arr = arr.slice(amount2, arr.length);
				var sumAmount2 = sum(arr, amount1);
				return sumAmount1 + sumAmount2;
			}
	}

var decrease = function(a,b)
	{
		return b - a;
	}
var toArrayNumber = function(arr)
	{
		for (var i = 0; i <= arr.length - 1; i++)
		{
			arr[i] = +arr[i];
		}
		return arr;
	}

{
var input1 = readline();
input1 = input1.split(' ');
var num1 = +input1[1], num2 = +input1[2];
var input2 = readline();
input2 = input2.split(' ');
input2 = toArrayNumber(input2);
input2 = input2.sort(decrease);
print(mainFunc(input2, num1, num2).toFixed(8));

}

function main() {
    var number1 = readline().split(' ');
    var a = readline().split(' ').map(function(val){return val * 1;});
    var n = number1[0], n1 = number1[1], n2 = number1[2];
    a.sort(function(a, b){return a - b});

    var sum1 = 0;
    for (var i = a.length - 1; i >= a.length - Math.min(n1, n2); --i) {
        sum1 += a[i];
    }

    var sum2 = 0;
    for (var j = a.length - 1 - Math.min(n1, n2); j >= a.length - n1 - n2; --j) {
        sum2 += a[j];
    }

    print(sum1 / Math.min(n1, n2) + sum2 / Math.max(n1, n2));
}

main();

function main(){
    var numbers = readline().split(" ");
    var max = Math.max(numbers[1],numbers[2]);
    var min = Math.min(numbers[1],numbers[2]);

    var vals = readline()
        .split(" ")
        .map(function(a){return a*1})
        .sort(function(a,b){return b-a});

    //print(JSON.stringify(vals))

    var avg1 = 0;
    var avg2 = 0;

    for(var i=0;i<min;i++){
        avg1+= vals.shift()/min;
    }

    for(i=0;i<max;i++){
        avg2+= vals.shift()/max;
    }

    // print(avg1/min+avg2/max,avg1,avg2,min,max);
    print(avg1+avg2);
}

main();

var maxAveragesSum = function( n1, n2, a ) {
  a.sort( (a, b) => b - a );
  var sum;
  if ( n1 < n2 ) {
    sum = a.slice( 0, n1 ).reduce( (a,b) => a + b, 0 ) / n1 + a.slice( n1, n2 + n1 ).reduce( (a,b) => a + b, 0 ) / n2;
  } else {
    sum = a.slice( 0, n2 ).reduce( (a,b) => a + b, 0 ) / n2 + a.slice( n2, n1 + n2 ).reduce( (a,b) => a + b, 0 ) / n1;
  }
  return sum;
};

var input = readline().split( " " ).map( i => parseInt( i, 10 ) );
var n = input[ 0 ];
var n1 = input[ 1 ];
var n2 = input[ 2 ];
var a = readline().split( " " ).map( i => parseInt( i, 10 ) );

print( maxAveragesSum( n1, n2, a ) );

var mainFunc = function(arr, amount1, amount2)
	{
		var sum = function(arr, amount)
		{
			var sumIn = 0;
			for (var i = 0; i <= amount - 1; i++)
			{
				sumIn += arr[i];
			}
			sumIn /= amount;
			return sumIn;
		}
		arr = arr.slice(0, amount1 + amount2 + 1);
		if (amount1 < amount2)
			{
				var sumAmount1 = sum(arr, amount1);
				arr = arr.slice(amount1 + 1, arr.length - 1);
				var sumAmount2 = sum(arr, amount2);
				return sumAmount1 + sumAmount2;
			}
		else
			{
				var sumAmount1 = sum(arr, amount2);
				arr = arr.slice(amount2, arr.length);
				var sumAmount2 = sum(arr, amount1);
				return sumAmount1 + sumAmount2;
			}
	}

var decrease = function(a,b)
	{
		return b - a;
	}
var toArrayNumber = function(arr)
	{
		for (var i = 0; i <= arr.length - 1; i++)
		{
			arr[i] = +arr[i];
		}
		return arr;
	}

{
var input1 = readline();
input1 = input1.split(' ');
var num1 = +input1[1], num2 = +input1[2];
var input2 = readline();
input2 = input2.split(' ');
input2 = toArrayNumber(input2);
input2 = input2.sort(decrease);
print(mainFunc(input2, num1, num2).toFixed(8));

}

    function sa(){
        var firstLine =readline().split(" ");
        var n1 = Math.min(Number(firstLine[1]), Number(firstLine[2]));
        var n2 = Math.max(Number(firstLine[1]), Number(firstLine[2]));
        var n = Number(firstLine[1]) + Number(firstLine[2]);
        var data = readline().split(" ").map(Number);
        data.sort().reverse();
        print(data);
        var sum = 0;
        var sum1 = 0;
        var sum2 = 0;
        for(var i=0;i<n;i++){
            if(i<n1){
                sum1 += data[i];
            } else {
                sum2 += data[i];
            }
        }

        print(sum1/n1 + sum2/n2)
    }
    sa();

    function sa(){
        var firstLine =readline().split(" ");
        var n1 = Math.min(Number(firstLine[1]), Number(firstLine[2]));
        var n2 = Math.max(Number(firstLine[1]), Number(firstLine[2]));
        var n = Number(firstLine[1]) + Number(firstLine[2]);
        var data = readline().split(" ").map(Number);
        data.sort().reverse();
        var sum = 0;
        var sum1 = 0;
        var sum2 = 0;
        for(var i=0;i<n;i++){
            if(i<n1){
                sum1 += data[i];
            } else {
                sum2 += data[i];
            }
        }

        print(sum1/n1 + sum2/n2)
    }
    sa();

function main() {
    var number1 = readline().split(' ');
    var a = readline().split(' ');
    var n = number1[0], n1 = number1[1], n2 = number1[2];
    a.sort();

    var sum1 = 0;
    for (var i = a.length - 1; i >= a.length - Math.min(n1, n2); --i) {
        sum1 += a[i] * 1;
    }

    var sum2 = 0;
    for (var i = a.length - 1 - Math.min(n1, n2); i >= a.length - n1 - n2; --i) {
        sum2 += a[i] * 1;
    }

    print(sum1, sum2);
    print(sum1 / Math.min(n1, n2) + sum2 / Math.max(n1, n2));
}

main();

function main() {
    var number1 = readline().split(' ');
    var a = readline().split(' ');
    var n = number1[0], n1 = number1[1], n2 = number1[2];
    a.sort();

    var sum1 = 0;
    for (var i = a.length - 1; i >= a.length - Math.min(n1, n2); --i) {
        sum1 += a[i] * 1;
    }

    var sum2 = 0;
    for (var j = a.length - 1 - Math.min(n1, n2); j >= a.length - n1 - n2; --j) {
        sum2 += a[j] * 1;
    }

    print(sum1 / Math.min(n1, n2) + sum2 / Math.max(n1, n2));
}

main();

function main() {
    var number1 = readline().split(' ');
    var a = readline().split(' ').map(function(val){return val * 1;});
    var n = number1[0], n1 = number1[1], n2 = number1[2];
    a.sort();

    var sum1 = 0;
    for (var i = a.length - 1; i >= a.length - Math.min(n1, n2); --i) {
        sum1 += a[i];
    }

    var sum2 = 0;
    for (var j = a.length - 1 - Math.min(n1, n2); j >= a.length - n1 - n2; --j) {
        sum2 += a[j];
    }

    print(sum1 / Math.min(n1, n2) + sum2 / Math.max(n1, n2));
}

main();

function main(){
    var numbers = readline().split(" ");
    var max = Math.max(numbers[1],numbers[2]);
    var min = Math.min(numbers[1],numbers[2]);

    var vals = readline().split(" ").map(function(a){return a*1}).sort(function(a,b){return a<b});

    var avg1 = 0;
    var avg2 = 0;

    for(var i=0;i<min;i++){
        avg1+=vals.shift()/min;
    }

    for(i=0;i<max;i++){
        avg2+=vals.shift()/max;
    }

    // print(avg1/min+avg2/max,avg1,avg2,min,max);
    print(avg1+avg2);
}

main();

function main(){
    var numbers = readline().split(" ");
    var max = Math.max(numbers[1],numbers[2]);
    var min = Math.min(numbers[1],numbers[2]);

    var vals = readline().split(" ").map(function(a){return a*1}).sort(function(a,b){return a<b});

    var avg1 = 0;
    var avg2 = 0;

    for(var i=0;i<min;i++){
        avg1+=vals.shift();
    }

    for(i=0;i<max;i++){
        avg2+=vals.shift();
    }

    // print(avg1/min+avg2/max,avg1,avg2,min,max);
    print(avg1/min+avg2/max);
}

main();

"use strict";
/*
let kk = 0;
let readline = function() {
	switch(kk++) {
		case 0: return '4 2 1';
		case 1: return '1 4 2 3';
	}
};
let write = console.log.bind();
*/

Array.prototype.sum = function(arr) {
	let s = 0;
	for ( let i = 0; i < this.length; i++ )
		s += this[i];

	return s;
};

let input = readline().split(' ').map(e => +e),
	n = input[0],
	n1 = input[1],
	n2 = input[2],
	A = readline().split(' ').map(e => +e).sort(),
	min = Math.min(n1, n2),
	max = n1 === min ? n2 : n1;

let opti = A.splice(-min).sum()/min;
opti += A.splice(-max).sum()/max;

write(opti)


var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function findAllStr(json, map, mapRev, index) {
   mapRev[index] = json;
   if (Array.isArray(json)) {
      for (var i = typeof json[0] === 'string' ? 1 : 0; i < json.length; i++) {
         findAllStr(json[i], map, mapRev, index + '_' + i);
      }
      return;
   }
   if (json && typeof json === 'string') {
      if (map[json]) {
         map[json].push(index);
      } else {
         map[json] = [index];
      }
   }
   return;
}

function solve() {
   var n2 = (Number(read()) >> 1);
   read();
   write(n2 * 6);
   for (var i = 0; i < n2; i++) {
      var a = i + 1;
      var b = n2 * 2 - i;
      var swapStr = a + ' ' + b;
      write('1 ' + swapStr);
      write('2 ' + swapStr);
      write('1 ' + swapStr);
      write('2 ' + swapStr);
      write('1 ' + swapStr);
      write('2 ' + swapStr);
   }
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}

const solve = () => {
  const gcd = (a, b) => (a % b === 0 ? b : gcd(b, a % b));
  let t = parseInt(readline());
  while (t--) {
       let n = parseInt(readline());
       let arr = readline().trim().split(" ").map(cur=>parseInt(cur));
       let res = [];
       for(let i=0;i<n;i+=2){
            let p1 = arr[i],p2 = arr[i+1];
            let k = [];
            while((p1!==(-1*arr[i]))||(p2!==(-1*arr[i+1]))){
                 p1 = p1+p2;
                 res.push(`1 ${i+1} ${i+1+1}`);
                 p2 = p2 - p1;
                 res.push(`2 ${i+1} ${i+1+1}`);
            }
       }
       console.log(res.length);
       for(let i=0;i<res.length;i++) console.log(res[i]);
  }
};
solve();

"use strict";
const fs = require("fs");
//let filename = "0.txt";
let filename = 0;
const input = fs.readFileSync(filename, "utf8").trim().split("\n");
let line = 0;
function readline() {
  return input[line++];
}

const solve = () => {
  let t = parseInt(readline());
  while (t--) {
    let n = parseInt(readline());
    let arr = readline()
      .trim()
      .split(" ")
      .map((cur) => parseInt(cur));
    let dp = [];
    dp[0] = 0;
    let pm = 0;
    for (let i = 1; i < n; i++) {
      dp[i] = arr[pm] === Math.max(arr[i - 1], arr[pm]) ? pm : i - 1;
      pm = arr[pm] === Math.max(arr[i], arr[pm]) ? pm : i;
    }
    let res = [];
    for (let i = n - 1; i >= 1; i--) {
      while (arr[i] >= 0) {
        res.push(`2 ${dp[i] + 1} ${i + 1}`);
        arr[i] -= arr[dp[i]];
      }
    }
    let max = 1;
    for (let i = 1; i < n; i++) {
      if (Math.abs(arr[i]) >= Math.abs(arr[max])) max = i;
    }
    while (arr[0] >= 0) {
      res.push(`1 1 ${max + 1}`);
      arr[0] += arr[max];
    }
    console.log(res.length);
    for (let i = 0; i < res.length; i++) console.log(res[i]);
  }
};
solve();

var timer = 0;
function dfs(v, prev) {
   var h = {};
   v.__h = h;
   h.tin = ++timer;
   h.up = [];
   var i = 0;
   var next = prev;
   while (next) {
      h.up[i] = next;
      next = next.__h.up[i++];
   }
   var children = v.childNodes;
   for (i = 0; i < children.length; i++) {
      dfs(children[i], v);
   }
   h.tout = ++timer;
}

function findAllStr(json, map, mapRev, index) {
   mapRev[index] = json;
   if (Array.isArray(json)) {
      for (var i = typeof json[0] === 'string' ? 1 : 0; i < json.length; i++) {
         findAllStr(json[i], map, mapRev, index + '_' + i);
      }
      return;
   }
   if (json && typeof json === 'string') {
      if (map[json]) {
         map[json].push(index);
      } else {
         map[json] = [index];
      }
   }
   return;
}

function solve() {
   var n2 = (Number(read()) >> 1);
   read();
   write(n2 * 6);
   for (var i = 0; i < n2; i++) {
      var a = i + 1;
      var b = n2 * 2 - i;
      var swapStr = a + ' ' + b;
      write('1 ' + swapStr);
      write('2 ' + swapStr);
      write('2 ' + swapStr);
      write('1 ' + swapStr);
      write('1 ' + swapStr);
      write('2 ' + swapStr);
   }
}

function init() {
   var T;
   T = 1;
   T = Number(read());
   for (var t = 0; t < T; t++) {
      solve();
   }
}

function sortF(a, b) {
   if (a < b) {
      return -1;
   }
   if (a > b) {
      return 1;
   }
   return 0;
}

function readArray(f) {
   return read().split(' ').map(f);
}

var isNode = typeof console !== 'undefined';
var MEMORY = [];
var MEMORY_INDEX = 0;
if (isNode) {
   var fs = require('fs');
   var path = require('path');

   var inTextName;
   var outTextName;

   var needWriteFile = false;

   var writeResult = '';
   if (process.argv.length === 5) {
      inTextName = process.argv[3];
      outTextName = process.argv[4];
   }

   if (inTextName) {
      fs.readFile(path.join(__dirname, inTextName), 'utf8', (err, data) => {
         MEMORY = data.split('\r\n');
         init();
         if (needWriteFile) {
            fs.writeFile(path.join(__dirname, outTextName), writeResult, (err) => {
               err ? console.error(err) : console.log('good')
            });
         }
      });
   } else {
      MEMORY = fs.readFileSync(0, 'utf-8').split('\r\n');
      init();
   }
} else {
   init();
}

function write(value) {
   if (needWriteFile) {
      writeResult += value + '\n';
      return;
   }
   isNode ? console.log('' + value) : print('' + value);
}
function read() {
   return isNode ? MEMORY[MEMORY_INDEX++] : readline();
}
function readAll() {
   return isNode && MEMORY;
}