#include <bits/stdc++.h>
using namespace std;
long long int INF = 1000000007;
long long int exp(long long int x, long long int n) {
  if (n == 0) return 1;
  if (n == 1) return x % INF;
  if (n % 2 == 0)
    return exp((x * x) % INF, n / 2);
  else
    return (x * exp((x * x) % INF, n / 2)) % INF;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t, i;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    long long int arr[n];
    for (i = 0; i < n; i++) cin >> arr[i];
    vector<long long int> ans;
    ans.push_back(arr[0]);
    for (i = 1; i < n - 1; i++) {
      if (i != 0 && i != n - 1) {
        if (arr[i - 1] < arr[i] && arr[i + 1] < arr[i]) ans.push_back(arr[i]);
        if (arr[i - 1] > arr[i] && arr[i + 1] > arr[i]) ans.push_back(arr[i]);
      }
    }
    ans.push_back(arr[n - 1]);
    cout << ans.size() << endl;
    for (i = 0; i < ans.size(); i++) {
      cout << ans[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
