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