#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (long long i = -0; i < n; i++) cin >> a[i];
    vector<long long> p;
    p.push_back(a[0]);
    for (long long i = 1; i < n - 1; i++) {
      if (a[i] > a[i + 1] && a[i] > a[i - 1]) p.push_back(a[i]);
      if (a[i] < a[i + 1] && a[i] < a[i - 1]) p.push_back(a[i]);
    }
    p.push_back(a[n - 1]);
    cout << p.size() << endl;
    for (auto x : p) cout << x << " ";
    cout << endl;
  }
  return 0;
}
