#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, delta = 0;
    cin >> n;
    vector<int> v;
    int a, b;
    cin >> a >> b;
    v.push_back(a);
    v.push_back(b);
    delta = b - a;
    for (int i = 2; i < n; i++) {
      int c, dif;
      cin >> c;
      dif = c - v[v.size() - 1];
      if ((dif < 0 && delta < 0) || (dif > 0 && delta > 0)) {
        v[v.size() - 1] = c;
      } else {
        v.push_back(c);
      }
      delta = dif;
    }
    cout << v.size() << endl;
    for (int i = 0; i < v.size(); i++) {
      cout << v[i] << " ";
    }
    cout << endl;
  }
}
