#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 7;
int a[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int tc;
  cin >> tc;
  while (tc--) {
    int n;
    cin >> n;
    for (int i = 1; i <= n; ++i) cin >> a[i];
    vector<int> ans;
    ans.emplace_back(a[1]);
    int last = -1;
    for (int i = 2; i <= n; ++i) {
      if (last == -1) {
        last = a[i];
        continue;
      }
      if (last < ans.back() && a[i] < last) {
        last = a[i];
        continue;
      }
      if (last > ans.back() && a[i] > last) {
        last = a[i];
        continue;
      }
      ans.emplace_back(last);
      last = a[i];
    }
    ans.emplace_back(a[n]);
    cout << ans.size() << '\n';
    for (auto &v : ans) cout << v << ' ';
    cout << '\n';
  }
  return 0;
}
