#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

int main(void){
	int length;
	int max=0, min=0;
	int dif = 0;
	int step;
	char steps[256];
	char index[1001];
	int now;
	int next = 0;
	int i, n, m;

	scanf("%d", &length);
	for(i=0; i<length; i++){
		scanf("%d", &step);
		scanf("%s", steps);
		for(n=0; steps[n] != '\0'; n++){
			if(0 == isspace(steps[n])){  // スペースの時
				m = 0;
				now = next;
				next = atoi(index) 
			}else{
				m ++;
				index[m] = steps[n];
			}
			dif = now - next;
			if(dif < 0){
				max = abs(dif);
			}else if(dif > 0){
				min = abs(dif);
			}
		}
		printf("%d %d", max, min);
	}
	
	return 0;
}