#include <bits/stdc++.h>
using namespace std;
long long int n, p[100000 + 5];
int main() {
  int tc;
  cin >> tc;
  while (tc--) {
    cin >> n;
    set<int> pq;
    for (int i = 1; i <= n; i++) {
      cin >> p[i];
      pq.insert(i);
    }
    long long int ans = 0;
    for (int i = 1; i <= n - 1; i++) {
      ans += abs(p[i] - p[i + 1]);
    }
    for (int i = 2; i <= n - 1; i++) {
      if (ans - abs(p[i - 1] - p[i]) - abs(p[i] - p[i + 1]) +
              abs(p[i - 1] - p[i + 1]) >=
          ans) {
        ans = ans - abs(p[i - 1] - p[i]) - abs(p[i] - p[i + 1]) +
              abs(p[i - 1] - p[i + 1]);
        pq.erase(i);
      }
    }
    cout << pq.size() << endl;
    for (auto x : pq) {
      cout << p[x] << " ";
    }
    cout << endl;
  }
  return 0;
}
