#include <bits/stdc++.h>
using namespace std;
long long a, b, c, d, i, e, f, g, n, m, k, l, t, A[500005];
vector<long long> v;
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    for (long long i = 1; i <= n; i++) {
      cin >> A[i];
    }
    v.clear();
    v.push_back(A[1]);
    v.push_back(A[2]);
    for (long long i = 3; i <= n; i++) {
      if (v[v.size() - 1] > v[v.size() - 2] && A[i] > v[v.size() - 1]) {
        v.pop_back();
        v.push_back(A[i]);
        continue;
      }
      if (v[v.size() - 1] < v[v.size() - 2] && A[i] < v[v.size() - 1]) {
        v.pop_back();
        v.push_back(A[i]);
        continue;
      }
      v.push_back(A[i]);
    }
    cout << v.size() << endl;
    for (long long i = 0; i < v.size(); i++) cout << v[i] << " ";
    cout << endl;
  }
}
