#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) {
      cin >> a[i];
    }
    vector<int> ans;
    ans.push_back(a[0]);
    for (int i = 0; i + 1 < n; i++) {
      int j = i + 1;
      while (j < n && (a[i + 1] - a[i] >= 0) == (a[j] - a[j - 1] >= 0)) {
        j++;
      }
      ans.push_back(a[j - 1]);
      i = j - 2;
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) {
      cout << ans[i] << " ";
    }
    cout << endl;
  }
}
