#include <bits/stdc++.h>
using namespace std;
long long t, n, i, nr, st, val;
long long si, sp;
char ch;
vector<int> ans;
int a[100005];
int b[100005];
void upd(int r) {
  nr++;
  swap(sp, si);
  si += r;
}
long long fval(int i) {
  long long ans;
  if (nr % 2 == 0) {
    ans = sp - si + i;
    ans = a[ans];
  } else {
    ans = si - sp - i + 1;
    ans = a[ans] ^ 1;
  }
  return ans;
}
int main() {
  cin >> t;
  while (t) {
    t--;
    cin >> n;
    for (i = 1; i <= n; i++) {
      cin >> ch;
      a[i] = ch - '0';
    }
    for (i = 1; i <= n; i++) {
      cin >> ch;
      b[i] = ch - '0';
    }
    sp = si = 0;
    st = a[1];
    nr = 0;
    ans.clear();
    for (i = n; i >= 1; i--) {
      val = fval(i);
      if (val == b[i]) continue;
      if (st != val) {
        ans.push_back(1);
        st ^= 1;
      }
      ans.push_back(i);
      st ^= 1;
      upd(i);
    }
    cout << ans.size() << ' ';
    for (int it : ans) cout << it << ' ';
    cout << '\n';
  }
  return 0;
}
