#include <bits/stdc++.h>
using namespace std;
const int N = 500005;
const int inf = 1000000001;
int ara[N];
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%d", &ara[i]);
    int cnt = 0;
    for (int i = 1, j = 3; i <= n && j <= n; j++) {
      if (ara[i] < ara[j - 1] && ara[j - 1] < ara[j]) {
        ara[j - 1] = 0;
        cnt++;
      } else if (ara[i] > ara[j - 1] && ara[j - 1] > ara[j]) {
        ara[j - 1] = 0;
        cnt++;
      } else {
        i = j - 1;
      }
    }
    printf("%d\n", n - cnt);
    for (int i = 1; i <= n; i++) {
      if (ara[i]) printf("%d ", ara[i]);
    }
    printf("\n");
  }
}
