#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int main(int argc, char const *argv[]) {
  ios_base::sync_with_stdio(0);
  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];
    std::vector<long long> v;
    v.push_back(a[0]);
    for (long long i = 1; i < n - 1; i++) {
      if ((a[i] - a[i - 1]) * (a[i] - a[i + 1]) > 0) v.push_back(a[i]);
    }
    v.push_back(a[n - 1]);
    cout << v.size() << "\n";
    for (auto u : v) cout << u << " ";
    cout << "\n";
  }
  return 0;
}
