#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 10;
int main() {
  int n;
  scanf("%d", &(n));
  while (n--) {
    int t;
    scanf("%d", &(t));
    int a[maxn], b[maxn], c[maxn];
    for (int i = 0; i < t; i++) {
      scanf("%d", a + i);
      if (i != 0) b[i] = a[i] - a[i - 1];
    }
    int ops = 0;
    c[0] = a[0];
    for (int i = 1; i < t - 1; i++) {
      if ((b[i] > 0 && b[i + 1] < 0) || (b[i] < 0 && b[i + 1] > 0))
        c[++ops] = a[i];
    }
    c[++ops] = a[t - 1];
    printf("%d\n", ops + 1);
    for (int i = 0; i <= ops; i++) printf("%d ", c[i]);
    printf("\n");
  }
  return 0;
}
