#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int p[n];
    for (int i = 0; i < n; i++) cin >> p[i];
    vector<long long int> ans;
    if (p[0] > p[1]) {
      int c = 1;
      ans.push_back(p[0]);
      for (int i = 1; i < n; i++) {
        if (p[i - 1] < p[i] && c == 1) {
          ans.push_back(p[i - 1]);
          c = 0;
        }
        if (c == 0 && p[i - 1] > p[i]) {
          ans.push_back(p[i - 1]);
          c = 1;
        }
      }
    } else if (p[0] < p[1]) {
      int c = 1;
      ans.push_back(p[0]);
      for (int i = 1; i < n; i++) {
        if (p[i - 1] > p[i] && c == 1) {
          ans.push_back(p[i - 1]);
          c = 0;
        }
        if (c == 0 && p[i - 1] < p[i]) {
          ans.push_back(p[i - 1]);
          c = 1;
        }
      }
    }
    ans.push_back(p[n - 1]);
    cout << ans.size() << '\n';
    for (int i = 0; i < ans.size(); i++) cout << ans[i] << " ";
    cout << '\n';
  }
  return 0;
}
