#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <typename T>
using v2 = vector<vector<T>>;
template <typename T>
inline v2<T> fill(int r, int c, T t) {
  return v2<T>(r, vector<T>(c, t));
}
int sgn(int i) {
  if (i > 0) return 1;
  if (i < 0) return -1;
  return 0;
}
int n;
void solve() {
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  vector<bool> bad(n, false);
  for (int i = 1; i < n - 1; i++) {
    if (sgn(a[i] - a[i - 1]) != sgn(a[i] - a[i + 1])) bad[i] = true;
  }
  vector<int> b;
  for (int i = 0; i < n; i++) {
    if (!bad[i]) b.push_back(a[i]);
  }
  cout << b.size() << '\n';
  for (int i = 0; i < b.size(); i++) cout << b[i] << " ";
  cout << '\n';
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  for (int i = 0; i < T; i++) {
    solve();
  }
  return 0;
}
