#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long n;
  cin >> n;
  int arr[n + 4];
  for (int i = 0; i < n; i++) cin >> arr[i];
  vector<int> v;
  for (int i = 0; i < n; i++) {
    if (i == 0 || i == n - 1 || arr[i - 1] < arr[i] != arr[i] < arr[i + 1])
      v.push_back(arr[i]);
  }
  cout << v.size() << "\n";
  for (auto &x : v) cout << x << " ";
  cout << "\n";
}
int main() {
  long long t;
  cin >> t;
  while (t--) solve();
}
