#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int a;
    cin >> a;
    std::vector<int> v(a);
    for (int i = 0; i < a; ++i) {
      cin >> v[i];
    }
    std::vector<int> v2;
    for (int i = 0; i + 1 < a; ++i) {
      if (i == 0) {
        v2.push_back(v[i]);
      } else {
        if (abs(v2[v2.size() - 1] - v[i + 1]) ==
            abs(v2[v2.size() - 1] - v[i]) + abs(v[i] - v[i + 1])) {
        } else {
          v2.push_back(v[i]);
        }
      }
    }
    v2.push_back(v[a - 1]);
    cout << v2.size() << "\n";
    for (int i = 0; i < v2.size(); ++i) {
      cout << v2[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
