#include <bits/stdc++.h>
using namespace std;
int a[100003], b[100003];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
    b[0] = 1;
    b[1] = 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]))
        b[++b[0]] = a[i];
    }
    b[++b[0]] = a[n];
    printf("%d\n", b[0]);
    for (int i = 1; i <= b[0]; ++i) printf("%d ", b[i]);
    printf("\n");
  }
  return 0;
}
