#include <bits/stdc++.h>
using namespace std;
long long t, ans, n, m, k, x, y;
const int N = 2e5 + 10;
int a[N];
vector<int> v;
bool q;
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    v.push_back(a[0]);
    if (a[1] > a[0])
      q = 0;
    else
      q = 1;
    for (int i = 1; i < n; i++) {
      x = v.back();
      if (a[i] > x && q) {
        v.pop_back();
        v.push_back(a[i]);
      } else if (a[i] < x && !q) {
        v.pop_back();
        v.push_back(a[i]);
      } else {
        v.push_back(a[i]);
        q = !q;
      }
    }
    cout << v.size() << endl;
    reverse(v.begin(), v.end());
    while (!v.empty()) {
      cout << v.back() << " ";
      v.pop_back();
    }
    cout << endl;
  }
}
