#include <bits/stdc++.h>
using namespace std;
int n, t, a[100005];
vector<int> v;
int main() {
  scanf("%d", &t);
  while (t--) {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
    }
    if (n == 2) {
      printf("2\n");
      printf("%d %d\n", a[1], a[2]);
    } else {
      v.clear();
      v.push_back(a[1]);
      for (int i = 2; i < n; i++) {
        if ((a[i] > a[i - 1] && a[i] > a[i + 1]) ||
            (a[i] < a[i - 1] && a[i] < a[i + 1])) {
          v.push_back(a[i]);
        }
      }
      v.push_back(a[n]);
      printf("%d\n", (int)v.size());
      for (int i = 0; i < (int)v.size(); i++) printf("%d ", v[i]);
      printf("\n");
    }
  }
  return 0;
}
