#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t = 1;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> v(n);
    long long pos_1, pos_n;
    for (long long i = 0; i < n; i++) cin >> v[i];
    vector<long long> res;
    for (long long i = 0; i < n; i++) {
      if (i == 0 or i == n - 1)
        res.push_back(v[i]);
      else if (v[i] < v[i - 1] and v[i] < v[i + 1])
        res.push_back(v[i]);
      else if (v[i] > v[i - 1] and v[i] > v[i + 1])
        res.push_back(v[i]);
    }
    cout << res.size() << endl;
    for (auto it : res) cout << it << " ";
    cout << endl;
  }
}
