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