#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10, mod = 1e9 + 7;
const double eps = 1e-10;
template <typename T>
void read(T &x) {
  x = 0;
  char ch = getchar();
  long long first = 1;
  while (!isdigit(ch)) {
    if (ch == '-') first *= -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - 48;
    ch = getchar();
  }
  x *= first;
}
template <typename T, typename... Args>
void read(T &first, Args &...args) {
  read(first);
  read(args...);
}
int T, n, x;
int a[N];
bool vis[N];
int main() {
  read(T);
  while (T--) {
    memset(vis, 0, sizeof(vis));
    int l = 1, r = 2;
    bool poi = 0;
    read(n);
    for (int i = (1); i < (n + 1); ++i) read(a[i]);
    while (r <= n) {
      a[l] < a[r] ? poi = 0 : poi = 1;
      while (r <= n && a[r - 1] < a[r] && !poi) r++;
      while (r <= n && a[r - 1] > a[r] && poi) r++;
      vis[l] = vis[r - 1] = true;
      l = r - 1;
    }
    int num = 0;
    for (int i = (1); i < (n + 1); ++i)
      if (vis[i]) num++;
    cout << num << endl;
    for (int i = (1); i < (n + 1); ++i)
      if (vis[i]) cout << a[i] << " ";
    cout << endl;
  }
  return 0;
}
