#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> ans;
void Solve() {
  string a, b;
  long long n;
  cin >> n >> a >> b;
  a = ' ' + a;
  b = ' ' + b;
  long long l = 1;
  long long r = n, cnt = 1;
  vector<long long> ans(0);
  for (long long i = n; i >= 1; i--) {
    cnt++;
    long long fi = a[l];
    if (cnt & 1) fi = '1' + '0' - fi;
    if (fi == b[i]) {
      ans.push_back(1);
    }
    ans.push_back(i);
    if (l < r) {
      long long L = r;
      long long R = l + 1;
      l = L;
      r = R;
    } else {
      long long L = r;
      long long R = l - 1;
      l = L;
      r = R;
    }
  }
  cout << ans.size() << ' ';
  for (auto i : ans) cout << i << ' ';
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  if (fopen("test.inp", "r"))
    freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
  long long sotest;
  cin >> sotest;
  while (sotest--) Solve();
}
