#include <bits/stdc++.h>
using std::cin;
using std::cout;
using std::string;
int _, n, a[111111], b[111111];
int main() {
  std::ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> _;
  while (_--) {
    cin >> n;
    for (register int i = (1); i <= (n); ++i) cin >> a[i];
    for (register int i = (0); i <= (n); ++i) b[i] = 0;
    b[++b[0]] = a[1];
    for (register int i = (2); i <= (n); ++i) {
      if (a[i] > a[i - 1]) {
        while (a[i + 1] > a[i] && i < n) ++i;
        b[++b[0]] = a[i];
        continue;
      } else {
        while (a[i + 1] < a[i] && i < n) ++i;
        b[++b[0]] = a[i];
        continue;
      }
    }
    cout << b[0] << "\n";
    for (register int i = (1); i <= (b[0]); ++i) cout << b[i] << " ";
    cout << "\n";
  }
  return 0;
}
