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