public static void main(String[] args) {
		StockMax sm = new StockMax();
		Scanner sc = new Scanner(System.in);
		int T = sc.nextInt();
		while (T-- > 0) {
			int N = sc.nextInt();
			int[] ar = new int[N];
			for (int i = 0; i < N; i++) {
				ar[i] = sc.nextInt();
			}
			System.out.println(sm.calMaxProfit(ar));
		}
	}