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