#include <bits/stdc++.h>
const int maxn = 2e6 + 10;
const int mod = 1e9 + 7;
using namespace std;
int n, m, k;
int a[maxn], b[maxn];
int num[30];
char s[maxn];
vector<int> g;
void solve() {
  g.clear();
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  g.push_back(a[0]);
  for (int pos = 1; pos < n - 1; pos++) {
    if ((a[pos] > a[pos - 1]) ^ (a[pos + 1] > a[pos])) g.push_back(a[pos]);
  }
  g.push_back(a[n - 1]);
  printf("%d\n", g.size());
  for (int i : g) printf("%d ", i);
  printf("\n");
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) solve();
  return 0;
}
