function main(input) {
  const lines = input.split('\n');
  lines.pop();
  // const n = lines[0];
  delete lines[0];
  const all = lines.slice(0, lines.length).map(v => {
    return parseInt(v, 10);
  }),
    sorted = lines.sort().map(v => {
      return parseInt(v, 10);
    });
  all.shift();
  sorted.pop();
  sorted.reverse();
  all.forEach(v => {
    console.log(fn(v, sorted));
  });
}

function fn(v, list) {
  for(var i = 0; v <= list[i]; i++) {
    if (v === list[i]) {
      return list[i+1];
    }
    if (v < list[i]) {
      return list[i];
    }
  }
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));
