#include <bits/stdc++.h>
using namespace std;
const int s = int(2e5 + 7);
void solve() {
  int n;
  cin >> n;
  int arr[s];
  vector<int> vi;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  int d = 0, in = 0;
  vi.push_back(arr[1]);
  for (int i = 2; i <= n; i++) {
    if (arr[i] > arr[i - 1]) {
      in = 1;
      if (d == 1) {
        d = 0;
        vi.push_back(arr[i - 1]);
      }
    } else {
      d = 1;
      if (in == 1) {
        in = 0;
        vi.push_back(arr[i - 1]);
      }
    }
  }
  vi.push_back(arr[n]);
  cout << vi.size() << '\n';
  for (auto x : vi) {
    cout << x << " ";
  }
  cout << '\n';
}
int main() {
  int tt;
  cin >> tt;
  while (tt--) {
    solve();
  }
}
