#include <bits/stdc++.h>
using namespace std;
template <typename T>
void print(T a) {
  for (auto x : a) cout << x << ' ';
  cout << endl;
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for (long long i = 0; i < n; i++) cin >> a[i];
  vector<long long> id;
  id.push_back(0);
  for (long long i = 1; i < n - 1; i++) {
    if (a[i - 1] < a[i] && a[i] < a[i + 1]) continue;
    if (a[i - 1] > a[i] && a[i] > a[i + 1]) continue;
    id.push_back(i);
  }
  id.push_back(n - 1);
  cout << (long long)(id).size() << '\n';
  for (long long x : id) cout << a[x] << ' ';
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  cin >> t;
  for (long long i = 0; i < t; i++) {
    solve();
  }
  return 0;
}
