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