#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<int> ans;
    int l = 0, r = n - 1, x = 0;
    for (int i = n - 1; i >= 0; --i) {
      int cur = (a[r] - '0') ^ x;
      if (cur == (b[i] - '0')) {
        if (l < r)
          --r;
        else
          ++r;
        continue;
      }
      cur = (a[l] - '0') ^ x;
      if (cur == (b[i] - '0')) {
        ans.push_back(1);
      }
      ans.push_back(i + 1);
      x ^= 1;
      swap(l, r);
      if (l < r)
        --r;
      else
        ++r;
    }
    cout << ans.size() << " ";
    for (auto i : ans) cout << i << " ";
    cout << '\n';
  }
}
