#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    int i = 0;
    vector<int> ans;
    ans.push_back(v[0]);
    while (i < n - 1) {
      int j = i;
      while ((i < n - 1) && (v[i + 1] > v[i])) i++;
      if (i != j) {
        ans.push_back(v[i]);
      }
      j = i;
      while ((i < n - 1) && (v[i + 1] < v[i])) i++;
      if (i != j) {
        ans.push_back(v[i]);
      }
    }
    cout << ans.size() << endl;
    for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
    cout << endl;
  }
}
