#include <bits/stdc++.h>
using namespace std;
const int OO = 1e7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> arr(n);
    for (int i = 0; i < n; i++) cin >> arr[i];
    vector<int> ans;
    ans.push_back(arr[0]);
    for (int i = 1; i < n - 1; i++) {
      if ((arr[i] > arr[i - 1] && arr[i] > arr[i + 1]) ||
          (arr[i] < arr[i - 1] && arr[i] < arr[i + 1]))
        ans.push_back(arr[i]);
    }
    ans.push_back(arr[n - 1]);
    cout << ans.size() << endl;
    for (auto i : ans) cout << i << " ";
    cout << endl;
  }
  return 0;
}
