#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int i, j, n, t;
  cin >> t;
  while (t--) {
    cin >> n;
    int a[n], x;
    vector<int> v;
    for (i = 0; i < n; i++) cin >> a[i];
    i = 0;
    while (i < n) {
      if (i + 1 >= n) break;
      if (a[i + 1] > a[i])
        x = 1;
      else
        x = 0;
      j = i + 1;
      if (x == 0) {
        while (j < n and a[j] < a[j - 1]) j++;
        if (v.size() == 0 or (v.size() > 0 and a[i] != v[v.size() - 1]))
          v.push_back(a[i]);
        v.push_back(a[j - 1]);
        i = j - 1;
      } else {
        while (j < n and a[j] > a[j - 1]) j++;
        if (v.size() == 0 or (v.size() > 0 and a[i] != v[v.size() - 1]))
          v.push_back(a[i]);
        v.push_back(a[j - 1]);
        i = j - 1;
      }
    }
    cout << v.size() << '\n';
    for (auto elem : v) cout << elem << ' ';
    cout << '\n';
  }
  return 0;
}
