#include <bits/stdc++.h>
using namespace std;
int t, n, p;
vector<int> vec;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    vec.clear();
    int state = 0, pvs = 0;
    for (int i = 0; i < n; i++) {
      cin >> p;
      if (!i) {
        vec.push_back(p);
      } else {
        if (state == 0) {
          if (pvs < p) {
            state = 1;
          } else if (pvs > p) {
            state = 2;
          }
        } else if (state == 1) {
          if (pvs > p) {
            vec.push_back(pvs);
            state = 2;
          }
        } else {
          if (pvs < p) {
            vec.push_back(pvs);
            state = 1;
          }
        }
      }
      pvs = p;
    }
    vec.push_back(pvs);
    cout << vec.size() << '\n';
    for (int i = 0; i < vec.size(); i++) {
      if (i) {
        cout << " ";
      }
      cout << vec[i];
    }
    cout << '\n';
  }
  return 0;
}
