#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e9 + 9;
int main(void) {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout.precision(10);
  cout << fixed;
  unsigned int tet;
  cin >> tet;
  while (tet--) {
    int n;
    cin >> n;
    vector<int> a(n + 1), ans;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int i = 1;
    while (i < n) {
      if (a[i] < a[i + 1]) {
        ans.push_back(a[i]);
        while (i < n && a[i] < a[i + 1]) {
          i++;
        }
      }
      if (i < n && a[i] > a[i + 1]) {
        ans.push_back(a[i]);
        while (i < n && a[i] > a[i + 1]) {
          i++;
        }
      }
    }
    if (i <= n) ans.push_back(a[i]);
    cout << ans.size() << '\n';
    for (int i = 0; i < ans.size(); i++) {
      cout << ans[i] << " ";
    }
    cout << '\n';
  }
  return 0;
}
