#include <bits/stdc++.h>
using namespace std;
const long long int mod = (1e9) + 7;
void solve() {
  long long int n;
  cin >> n;
  vector<long long int> arr(n, 0);
  for (long long int i = 0; i < n; i++) {
    cin >> arr[i];
  }
  if (n == 2) {
    if (arr[0] == arr[1]) {
      cout << 0 << endl;
      return;
    }
    cout << 2 << endl;
    cout << arr[0] << " " << arr[1] << endl;
    return;
  }
  vector<long long int> ans;
  ans.push_back(arr[0]);
  long long int trend = ((arr[1] - arr[0]) >= 0) ? 1 : -1;
  for (long long int i = 1; i < n; i++) {
    long long int temp = ((arr[i] - arr[i - 1]) >= 0) ? 1 : -1;
    if ((temp * trend) >= 0) {
      continue;
    } else {
      ans.push_back(arr[i - 1]);
      trend = -trend;
    }
  }
  if (n > 2) ans.push_back(arr[n - 1]);
  cout << ans.size() << endl;
  for (auto i : ans) {
    cout << i << " ";
  }
  cout << endl;
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
