import java.util.*;
class OldSchoolHero {
public static List<Integer> minOperations(int T, List<int[]> testCases) {
List<Integer> results = new ArrayList<>();
for (int t = 0; t < T; t++) {
int[] boxes = testCases.get(t);
int minValue
= Arrays.
stream(boxes
).
min().
getAsInt();
// Try all target values from `minValue` to `minValue - 5` (inclusive)
for (int target = minValue; target >= minValue - 5; target--) {
int currentOps = 0;
for (int box : boxes) {
int diff = box - target;
// Convert the difference to operations: using 5, 2, and 1 denomination
currentOps += diff / 5 + (diff % 5) / 2 + (diff % 5) % 2;
}
totalOps
= Math.
min(totalOps, currentOps
); }
results.add(totalOps);
}
return results;
}
public static void main
(String[] args
) { Scanner sc
= new Scanner
(System.
in);
int T = sc.nextInt();
List<int[]> testCases = new ArrayList<>();
for (int i = 0; i < T; i++) {
int M = sc.nextInt();
int[] boxes = new int[M];
for (int j = 0; j < M; j++) {
boxes[j] = sc.nextInt();
}
testCases.add(boxes);
}
List<Integer> results = minOperations(T, testCases);
for (int res : results) {
}
sc.close();
}
}
aW1wb3J0IGphdmEudXRpbC4qOwoKY2xhc3MgT2xkU2Nob29sSGVybyB7CiAgICBwdWJsaWMgc3RhdGljIExpc3Q8SW50ZWdlcj4gbWluT3BlcmF0aW9ucyhpbnQgVCwgTGlzdDxpbnRbXT4gdGVzdENhc2VzKSB7CiAgICAgICAgTGlzdDxJbnRlZ2VyPiByZXN1bHRzID0gbmV3IEFycmF5TGlzdDw+KCk7CiAgICAgICAgCiAgICAgICAgZm9yIChpbnQgdCA9IDA7IHQgPCBUOyB0KyspIHsKICAgICAgICAgICAgaW50W10gYm94ZXMgPSB0ZXN0Q2FzZXMuZ2V0KHQpOwogICAgICAgICAgICBpbnQgbWluVmFsdWUgPSBBcnJheXMuc3RyZWFtKGJveGVzKS5taW4oKS5nZXRBc0ludCgpOwogICAgICAgICAgICBpbnQgdG90YWxPcHMgPSBJbnRlZ2VyLk1BWF9WQUxVRTsKCiAgICAgICAgICAgIC8vIFRyeSBhbGwgdGFyZ2V0IHZhbHVlcyBmcm9tIGBtaW5WYWx1ZWAgdG8gYG1pblZhbHVlIC0gNWAgKGluY2x1c2l2ZSkKICAgICAgICAgICAgZm9yIChpbnQgdGFyZ2V0ID0gbWluVmFsdWU7IHRhcmdldCA+PSBtaW5WYWx1ZSAtIDU7IHRhcmdldC0tKSB7CiAgICAgICAgICAgICAgICBpbnQgY3VycmVudE9wcyA9IDA7CgogICAgICAgICAgICAgICAgZm9yIChpbnQgYm94IDogYm94ZXMpIHsKICAgICAgICAgICAgICAgICAgICBpbnQgZGlmZiA9IGJveCAtIHRhcmdldDsKCiAgICAgICAgICAgICAgICAgICAgLy8gQ29udmVydCB0aGUgZGlmZmVyZW5jZSB0byBvcGVyYXRpb25zOiB1c2luZyA1LCAyLCBhbmQgMSBkZW5vbWluYXRpb24KICAgICAgICAgICAgICAgICAgICBjdXJyZW50T3BzICs9IGRpZmYgLyA1ICsgKGRpZmYgJSA1KSAvIDIgKyAoZGlmZiAlIDUpICUgMjsKICAgICAgICAgICAgICAgIH0KCiAgICAgICAgICAgICAgICB0b3RhbE9wcyA9IE1hdGgubWluKHRvdGFsT3BzLCBjdXJyZW50T3BzKTsKICAgICAgICAgICAgfQogICAgICAgICAgICAKICAgICAgICAgICAgcmVzdWx0cy5hZGQodG90YWxPcHMpOwogICAgICAgIH0KICAgICAgICAKICAgICAgICByZXR1cm4gcmVzdWx0czsKICAgIH0KCiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgU2Nhbm5lciBzYyA9IG5ldyBTY2FubmVyKFN5c3RlbS5pbik7CiAgICAgICAgCiAgICAgICAgaW50IFQgPSBzYy5uZXh0SW50KCk7CiAgICAgICAgTGlzdDxpbnRbXT4gdGVzdENhc2VzID0gbmV3IEFycmF5TGlzdDw+KCk7CiAgICAgICAgCiAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCBUOyBpKyspIHsKICAgICAgICAgICAgaW50IE0gPSBzYy5uZXh0SW50KCk7CiAgICAgICAgICAgIGludFtdIGJveGVzID0gbmV3IGludFtNXTsKICAgICAgICAgICAgZm9yIChpbnQgaiA9IDA7IGogPCBNOyBqKyspIHsKICAgICAgICAgICAgICAgIGJveGVzW2pdID0gc2MubmV4dEludCgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIHRlc3RDYXNlcy5hZGQoYm94ZXMpOwogICAgICAgIH0KICAgICAgICAKICAgICAgICBMaXN0PEludGVnZXI+IHJlc3VsdHMgPSBtaW5PcGVyYXRpb25zKFQsIHRlc3RDYXNlcyk7CiAgICAgICAgZm9yIChpbnQgcmVzIDogcmVzdWx0cykgewogICAgICAgICAgICBTeXN0ZW0ub3V0LnByaW50bG4ocmVzKTsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgc2MuY2xvc2UoKTsKICAgIH0KfQo=