#include <bits/stdc++.h>
using namespace std;
long long int power(long long int a, long long int b) {
  if (b == 0) return 1;
  if (b % 2 == 0) return (power((a * a) % 998244353, b / 2)) % 998244353;
  return (a * (power((a * a) % 998244353, b / 2)) % 998244353) % 998244353;
}
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int modInv(int n) { return power(n, 1000000007 - 2); }
int nCr(int n, int r, int p = 1000000007) {
  if (r == 0) return 1;
  int Fact[n + 1];
  Fact[0] = 1;
  for (int i = 1; i <= n; i++) {
    Fact[i] = (Fact[i - 1] * i) % p;
  }
  return (((Fact[n] * modInv(Fact[r])) % 1000000007) *
          (modInv(Fact[n - r]) % 1000000007)) %
         1000000007;
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    int n, i, j;
    cin >> n;
    int a[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    vector<int> ans;
    ans.push_back(a[0]);
    ans.push_back(a[1]);
    int q = a[1] - a[0];
    for (i = 2; i < n; i++) {
      int r = a[i] - a[i - 1];
      if ((r > 0 && q > 0) || (r < 0 && q < 0))
        ans.back() = a[i];
      else
        ans.push_back(a[i]);
      q = r;
    }
    cout << ans.size() << "\n";
    for (i = 0; i < ans.size(); i++) {
      cout << ans[i] << " ";
    }
    cout << "\n";
  }
}
