#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int a[maxn], vis[maxn];
int main() {
  int t;
  cin >> t;
  while (t--) {
    memset(vis, 0, sizeof(vis));
    int n;
    cin >> n;
    a[0] = 0;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int ans = n;
    for (int i = 2; i < n; i++) {
      if ((a[i] >= a[i - 1] && a[i] <= a[i + 1]) ||
          (a[i] >= a[i + 1] && a[i] <= a[i - 1])) {
        vis[i]++;
        ans--;
      }
    }
    cout << ans << endl;
    for (int i = 1; i <= n; i++) {
      if (!vis[i]) cout << a[i] << " ";
    }
    cout << endl;
  }
}
