#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    vector<int> ans, p(n);
    for (int i = 0; i < n; i++) cin >> p[i];
    for (int i = 1; i <= n; i++) {
      if (i == 1 || i == n || (p[i - 2] < p[i - 1]) != (p[i - 1] < p[i]))
        ans.push_back(p[i - 1]);
    }
    cout << ans.size() << "\n";
    for (int i : ans) cout << i << " ";
    cout << "\n";
  }
}
