#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios_base::sync_with_stdio();
  cin.tie(0);
  cout.tie(0);
  ;
  int test;
  cin >> test;
  while (test--) {
    int n;
    cin >> n;
    int a[n];
    for (__typeof(n) i = 0; i < n; i++) {
      cin >> a[i];
    }
    if (n == 2) {
      cout << 2 << endl << a[0] << " " << a[1] << endl;
      continue;
    }
    vector<int> ans;
    ans.push_back(a[0]);
    int flag;
    if (a[0] > a[1])
      flag = 1;
    else
      flag = 0;
    for (__typeof(n) i = 2; i < n; i++) {
      if (a[i] > a[i - 1] && flag == 1) {
        ans.push_back(a[i - 1]);
        flag = 0;
      } else if (a[i] < a[i - 1] && flag == 0) {
        ans.push_back(a[i - 1]);
        flag = 1;
      }
    }
    ans.push_back(a[n - 1]);
    cout << ans.size() << endl;
    for (__typeof((int)ans.size()) i = 0; i < (int)ans.size(); i++) {
      cout << ans[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
