#include <bits/stdc++.h>
using namespace std;
int32_t main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    vector<long long> a(n), b(n);
    for (long long i = 0; i < n; i++) {
      a[i] = s1[i] - '0';
      b[i] = s2[i] - '0';
    }
    long long l = 0, r = n - 1;
    long long rv = 0, cur = 0;
    vector<long long> ans;
    for (long long i = n - 1; i >= 0; i--) {
      if (rv == 0) {
        long long tt = a[r] ^ cur;
        ;
        if (tt == b[i]) {
          r--;
          continue;
        }
        tt = a[l] ^ cur;
        if (tt == b[i]) ans.push_back(1);
        ans.push_back(i + 1);
        cur ^= 1;
        l++;
        rv = (rv + 1) % 2;
      } else {
        long long tt = a[l] ^ cur;
        if (tt == b[i]) {
          l++;
          continue;
        }
        tt = a[r] ^ cur;
        if (tt == b[i]) ans.push_back(1);
        ans.push_back(i + 1);
        cur ^= 1;
        r--;
        rv = (rv + 1) % 2;
      }
    }
    assert(ans.size() <= 2 * n);
    cout << ans.size() << " ";
    for (long long &i : ans) cout << i << ' ';
    cout << "\n";
  }
}
