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

/*
 * Warmup Contest #2, September 4, 2010 Problem A 
 * Solution by James Koppel
 * Originally from http://www.acmgnyr.org/year2009/problems.shtml 
 * Greater New York ACM regional 2009 problem A
 * 
 * Sort the numbers in reverse order and pick the 3rd number.
 */

int a[10];

int cm(const void *a, const void *b) {
  return *(int*)b-*(int*)a;
}

int main() {
  int n;
  scanf("%d", &n);

  for(int times = 0; times < n; times++) {
    int t;
    scanf("%d", &t);

    for (int i = 0; i < 10; i++) {
      scanf("%d",&a[i]);
    }

    qsort(a, 10, sizeof(int), cm);

    printf("%d %d\n", t, a[2]);
  }

  return 0;
}
