#include <bits/stdc++.h>
using namespace std;
long long const N = 1e5 + 1;
void solve() {
  long long n;
  cin >> n;
  long long a[n];
  for (int i = 0; i < n; i++) cin >> a[i];
  vector<long long> ans;
  for (int i = 0; i < n;) {
    if (i == n - 1) {
      ans.push_back(a[i]);
      i++;
    } else {
      if (a[i + 1] > a[i]) {
        ans.push_back(a[i]);
        int j = i + 1;
        while (j < n && a[j] > a[i]) {
          i++;
          j++;
        }
      } else {
        ans.push_back(a[i]);
        int j = i + 1;
        while (j < n && a[j] < a[i]) {
          i++;
          j++;
        }
      }
    }
  }
  cout << ans.size() << "\n";
  for (int i = 0; i < ans.size(); i++) {
    cout << ans[i] << " ";
  }
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
