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