#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n;
  int p[100000];
  cin >> n;
  for (int i = 0; i < n; ++i) cin >> p[i];
  int k;
  int s[100000];
  k = 1;
  s[0] = p[0];
  int next_index = 1;
  while (next_index < n) {
    int delta = p[next_index] - p[next_index - 1];
    int delta_sign = delta > 0 ? 1 : -1;
    while (next_index < n &&
           (p[next_index] - p[next_index - 1]) * delta_sign > 0)
      ++next_index;
    s[k++] = p[next_index - 1];
  }
  cout << k << endl;
  for (int i = 0; i < k; ++i) cout << s[i] << ' ';
  cout << endl;
}
int main() {
  int t;
  cin >> t;
  for (int i = 0; i < t; ++i) solve();
  return 0;
}
