#include <bits/stdc++.h>
using namespace std;
long long mod = 998244353;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cout << fixed;
  cout.precision(12);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    vector<long long> a(n + 1);
    for (long long i = 1; i <= n; i++) cin >> a[i];
    vector<long long> an;
    an.push_back(a[1]);
    for (long long i = 2; i < n; i++) {
      if (((a[i] - a[i - 1]) * (a[i + 1] - a[i])) > 0) {
        continue;
      }
      an.push_back(a[i]);
    }
    an.push_back(a[n]);
    cout << an.size() << endl;
    for (int i = 0; i < an.size(); i++) cout << an[i] << " ";
    cout << endl;
  }
  return 0;
}
