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