#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int arr[n];
    for (int i = 0; i < n; i++) cin >> arr[i];
    if (n == 2) {
      cout << 2 << "\n";
      for (int i = 0; i < n; i++) cout << arr[i] << " ";
    } else {
      vector<int> index;
      index.push_back(0);
      int prev = 0, next = 2, mid = 1;
      while (next < n) {
        if (abs(arr[next] - arr[prev]) <
            (abs(arr[next] - arr[mid]) + abs(arr[mid] - arr[prev]))) {
          index.push_back(mid);
          prev = mid;
        }
        mid++;
        next++;
      }
      index.push_back(n - 1);
      cout << index.size() << "\n";
      for (int i = 0; i < index.size(); i++) cout << arr[index[i]] << " ";
    }
    cout << "\n";
  }
  return 0;
}
