#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    long long a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    vector<long long> ans;
    ans.push_back(a[0]);
    for (int i = 1; i < n - 1; i++) {
      if (a[i] > ans[ans.size() - 1]) {
        while (a[i + 1] > a[i]) {
          i++;
          if (i == n - 1) break;
        }
        if (i != n - 1) ans.push_back(a[i]);
      } else if (a[i] < ans[ans.size() - 1]) {
        while (a[i + 1] < a[i]) {
          i++;
          if (i == n - 1) break;
        }
        if (i != n - 1) ans.push_back(a[i]);
      }
    }
    ans.push_back(a[n - 1]);
    cout << ans.size() << endl;
    for (auto x : ans) cout << x << " ";
    cout << endl;
  }
  return 0;
}
