#include <bits/stdc++.h>
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  long long n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  vector<long long> c(n);
  for (long long i = 0; i < n; i++) {
    c[i] = (b[i] - '0');
  }
  vector<long long> p;
  long long cnt = 0;
  deque<long long> q;
  for (long long i = 0; i < n; i++) {
    q.push_back(a[i] - '0');
  }
  for (long long i = n - 1; i >= 0; i--) {
    if (cnt & 1) {
      long long ft = q.back();
      long long lt = q.front();
      ft ^= 1;
      lt ^= 1;
      if (lt == c[i]) {
        q.pop_front();
        continue;
      }
      if (ft == lt) {
        p.push_back(i + 1);
        q.pop_back();
        cnt++;
      } else {
        p.push_back(1);
        p.push_back(i + 1);
        q.pop_back();
        cnt++;
      }
    } else {
      long long ft = q.front();
      long long lt = q.back();
      if (lt == c[i]) {
        q.pop_back();
        continue;
      }
      if (ft == lt) {
        p.push_back(i + 1);
        q.pop_front();
        cnt++;
      } else {
        p.push_back(1);
        p.push_back(i + 1);
        q.pop_front();
        cnt++;
      }
    }
  }
  cout << (long long)(p).size() << " ";
  for (auto &el : p) {
    cout << el << " ";
  }
  cout << "\n";
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
