#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t = 1;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    vector<long long int> arr(n, 0);
    for_each(arr.begin(), arr.end(), [](long long int& x) { cin >> x; });
    bool less = true;
    if (arr[1] > arr[0]) {
      less = false;
    }
    vector<long long int> result;
    result.push_back(arr[0]);
    result.push_back(arr[1]);
    for (long long int i = 2; i < arr.size(); i++) {
      if (arr[i] > result[result.size() - 1] && less) {
        result.push_back(arr[i]);
        less = false;
      }
      if (arr[i] > result[result.size() - 1] && !less) {
        result.pop_back();
        result.push_back(arr[i]);
      }
      if (arr[i] < result[result.size() - 1] && less) {
        result.pop_back();
        result.push_back(arr[i]);
      }
      if (arr[i] < result[result.size() - 1] && !less) {
        result.push_back(arr[i]);
        less = true;
      }
    }
    cout << result.size() << "\n";
    for_each(result.begin(), result.end(),
             [](long long int x) { cout << x << " "; });
    cout << "\n";
  }
  return 0;
}
