#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  while (a && b) {
    if (a > b)
      a = a % b;
    else
      b = b % a;
  }
  return a + b;
}
long long fact(int n) {
  if (n == 0) return 1;
  return fact(n - 1) * n;
}
long long lcm(long long a, long long b) {
  long long temp = gcd(a, b);
  return temp ? (a / temp * b) : 0;
}
bool isPolindrom(string s) {
  for (int i = 0; i < s.length() / 2; ++i) {
    if (s[i] != s[s.length() - 1 - i]) return false;
  }
  return true;
}
void sch(map<int, map<int, int>> &a, int u, vector<int> &used) {
  for (auto it = a[u].begin(); it != a[u].end(); ++it) {
    if (!used[it->first]) {
      used[it->first] = 1;
      sch(a, it->first, used);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    int n, k = 0;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; ++i) cin >> a[i];
    for (int i = 1, j = 0; i < n - 1; ++i) {
      if (abs(a[j] - a[i + 1]) == abs(a[i] - a[j]) + abs(a[i] - a[i + 1])) {
        a[i] = 0;
        ++k;
      } else
        j = i;
    }
    cout << n - k << endl;
    for (int i = 0; i < n; ++i) {
      if (a[i]) cout << a[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
