#include <cstdio>
#include <iostream>
using namespace std;

int main()
{
	int n;

	while (scanf("%d", &n), n){
		for (int i = 0; i < n; i++){
			int num, sum = 0;
			for (int j = 0; j < 4; j++){
				scanf("%d", &num);
				sum += num;
				printf("%5d", num);
			}
			printf("%5d\n", sum);
		}
	}

	return (0);
}