#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  int t, n, a, b, c, d;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<int> v(n), w(n);
    d = 0;
    int e = 0, j = 0;
    for (int i = 0; i < n; i++) cin >> v[i];
    a = v[0], b = v[1];
    for (int i = 2; i < n; i++) {
      c = v[i];
      if ((b > a and v[i] > b) or (a > b and b > v[i]))
        b = v[i];
      else {
        w[j++] = a, a = b, b = c;
      }
    }
    w[j++] = a;
    w[j++] = b;
    cout << j << endl;
    for (int i = 0; i < j; i++) cout << w[i] << " ";
    cout << endl;
  }
  return 0;
}
