#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> a;
    for (int e = 0; e < n; e++) {
      int y;
      cin >> y;
      a.push_back(y);
    };
    int nc = (a[1] - a[0] > 0);
    vector<int> res;
    res.push_back(a[0]);
    for (int i = 2; i < n; i++) {
      if (nc == 1) {
        if (a[i] < a[i - 1]) {
          res.push_back(a[i - 1]);
          nc = 0;
        }
      } else {
        if (a[i] > a[i - 1]) {
          res.push_back(a[i - 1]);
          nc = 1;
        }
      }
    }
    res.push_back(a[n - 1]);
    cout << res.size() << endl;
    for (auto it = res.begin(); it != res.end(); it++) cout << *it << ' ';
    cout << '\n';
    ;
  }
}
