#include <bits/stdc++.h>
using namespace std;
void solve() {
  int i, j, k, n, m, ans = 0, cnt = 0, sum = 0;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<int> res;
  res.push_back(a[0]);
  int last = a[0], flag = 1;
  for (int i = 1; i < n - 1;) {
    if (abs(a[i] - last) + abs(a[i] - a[i + 1]) > abs(last - a[i + 1])) {
      res.push_back(a[i]);
      last = a[i];
      i++;
    } else
      i++;
  }
  if (flag) res.push_back(a[n - 1]);
  cout << res.size() << "\n";
  for (auto x : res) cout << x << " ";
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
