#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n;
char a[N], b[N];
vector<int> v;
deque<int> q;
void solve() {
  scanf("%d", &n);
  scanf("%s", a);
  scanf("%s", b);
  v.clear();
  q.clear();
  for (int i = 0; i < n; i++) q.push_back(a[i] - '0');
  int k = 0;
  int val = 0;
  for (int i = n - 1; i >= 0; i--) {
    if (k) {
      if (b[i] - '0' == (q.front() ^ val)) {
        q.pop_front();
        continue;
      }
      if ((q.back() ^ val) == b[i] - '0') {
        v.push_back(1);
      }
      q.pop_back();
      v.push_back(i + 1);
      k ^= 1;
      val ^= 1;
    } else {
      if (b[i] - '0' == q.back()) {
        q.pop_back();
        continue;
      }
      if ((q.front() ^ val) == b[i] - '0') {
        v.push_back(1);
      }
      q.pop_front();
      v.push_back(i + 1);
      k ^= 1;
      val ^= 1;
    }
  }
  printf("%d", (int)v.size());
  for (int i = 0; i < (int)v.size(); i++) {
    printf(" %d", v[i]);
  }
  puts("");
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
