#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline ostream &operator<<(ostream &_out, const vector<T> &_v) {
  if (_v.empty()) return _out;
  _out << _v.front();
  for (auto _it = ++_v.begin(); _it != _v.end(); ++_it) _out << ' ' << *_it;
  return _out;
}
template <typename T>
inline istream &operator>>(istream &_in, vector<T> &_v) {
  for (auto &_i : _v) _in >> _i;
  return _in;
}
template <typename T>
inline ostream &operator<<(ostream &_out, const set<T> &_s) {
  if (_s.empty()) return _out;
  _out << *_s.begin();
  for (auto _it = ++_s.begin(); _it != _s.end(); ++_it) _out << ' ' << *_it;
  return _out;
}
template <typename T, typename U>
inline ostream &operator<<(ostream &_out, const map<T, U> &_m) {
  if (_m.empty()) return _out;
  _out << '(' << _m.begin()->first << ": " << _m.begin()->second << ')';
  for (auto _it = ++_m.begin(); _it != _m.end(); ++_it)
    _out << ", (" << _it->first << ": " << _it->second << ')';
  return _out;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
inline void solve() {
  int n;
  cin >> n;
  vector<int> p(n);
  cin >> p;
  int begin_of_current_segment = 0;
  bool increase = p[1] > p[0];
  vector<bool> mask(n, false);
  for (int i = 2; i < n; ++i) {
    if (p[i] > p[i - 1]) {
      if (!increase) {
        increase = true;
        mask[begin_of_current_segment] = true;
        mask[i - 1] = true;
        begin_of_current_segment = i - 1;
      }
    } else {
      if (increase) {
        increase = false;
        mask[begin_of_current_segment] = true;
        mask[i - 1] = true;
        begin_of_current_segment = i - 1;
      }
    }
  }
  mask[begin_of_current_segment] = true;
  mask.back() = true;
  cout << accumulate(mask.begin(), mask.end(), 0) << "\n";
  for (int i = 0; i < n; ++i) {
    if (mask[i]) cout << p[i] << " ";
  }
  cout << "\n";
}
inline void tsolve() {
  int t;
  cin >> t;
  while (t--) solve();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  tsolve();
  return 0;
}
