#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int ans[100001];
    for (int i = 0; i < 100001; i++) ans[i] = -1;
    ans[0] = a[0];
    int i = 1, k = 1;
    while (i < n) {
      int flag1 = 0, flag2 = 0;
      while (a[i] > a[i - 1]) {
        flag1 = 1;
        ans[k] = a[i];
        i++;
        if (i == n) {
          flag1 = 0;
          break;
        }
      }
      if (i == n) break;
      if (flag1) {
        k++;
        ans[k] = a[i];
      }
      while (a[i] < a[i - 1]) {
        flag2 = 1;
        ans[k] = a[i];
        i++;
        if (i == n) {
          flag2 = 0;
          break;
        }
      }
      if (i == n) break;
      if (flag2) {
        k++;
        ans[k] = a[i];
      }
    }
    int len = k + 1;
    cout << len << endl;
    i = 0;
    for (; i < len; i++) cout << ans[i] << " ";
    cout << endl;
  }
  return 0;
}
