#include <bits/stdc++.h>
using namespace std;
typedef priority_queue<long long int> pq_max;
typedef priority_queue<long long int, vector<long long int>,
                       greater<long long int> >
    pq_min;
double pi = 2 * acos(0.0);
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
long long fast_power(long long base, long long power) {
  long long result = 1;
  while (power > 0) {
    if (power % 2 == 1) {
      result = (result * base) % 1000000007;
    }
    base = (base * base) % 1000000007;
    power = power / 2;
  }
  return result;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int TESTS;
  cin >> TESTS;
  while (TESTS--) {
    int n;
    cin >> n;
    std::vector<int> v(n);
    for (long long int i = 0; i < n; i++) {
      cin >> v[i];
    }
    int i = 1;
    auto it = v.begin();
    it++;
    while (i != n - 1) {
      if (v[i] > v[i - 1] && v[i] < v[i + 1]) {
        v.erase(it);
        n--;
      } else if (v[i] < v[i - 1] && v[i] > v[i + 1]) {
        v.erase(it);
        n--;
      } else {
        i++, it++;
      }
    }
    cout << n;
    cout << "\n";
    for (long long int i = 0; i < n; i++) {
      cout << v[i] << " ";
    }
    cout << "\n";
  }
}
