#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
long long mod_pow(long long a, long long n, long long mod) {
  long long res = 1;
  while (n) {
    if (n & 1) res = (res * a) % mod;
    n /= 2;
    a = (a * a) % mod;
  }
  return res;
}
void solve();
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) solve();
}
void solve() {
  long long n;
  cin >> n;
  vector<long long> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];
  int a = v[0], b = v[1];
  vector<int> ans(2);
  ans[0] = a, ans[1] = b;
  for (int i = 2; i < n; ++i) {
    if (a > b && b > v[i]) {
      ans.pop_back();
      ans.push_back(v[i]);
      b = v[i];
    } else if (b > a && v[i] > b) {
      ans.pop_back();
      ans.push_back(v[i]);
      b = v[i];
    } else {
      ans.push_back(v[i]);
      a = b;
      b = v[i];
    }
  }
  cout << ans.size() << "\n";
  for (auto i : ans) cout << i << " ";
  cout << "\n";
}
