#include <bits/stdc++.h>
using namespace std;
long long t, n, p;
int main() {
  cin.sync_with_stdio(0);
  cin.tie();
  cin.exceptions(cin.failbit);
  cin >> t;
  for (int i = 1; i <= t; i++) {
    cin >> n;
    vector<int> arr;
    for (int j = 1; j <= n; j++) {
      cin >> p;
      arr.push_back(p);
    }
    if (arr.size() == 2) {
      cout << 2 << endl << arr[0] << " " << arr[1] << endl;
      continue;
    }
    long long sl = arr[0];
    long long l = arr[1];
    stack<long long> s;
    s.push(sl);
    s.push(l);
    for (int i = 2; i <= n - 1; i++) {
      int curr = arr[i];
      if ((curr - l) * (l - sl) >= 0) {
        s.pop();
      } else {
        sl = l;
      }
      s.push(curr);
      l = curr;
    }
    vector<int> sub;
    while (!s.empty()) {
      sub.push_back(s.top());
      s.pop();
    }
    reverse(begin(sub), end(sub));
    cout << sub.size() << endl;
    for (auto& k : sub) {
      cout << k << " ";
    }
    cout << endl;
  }
}
