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