#include <bits/stdc++.h>
using namespace std;
int t;
int n;
string a, b;
char inv(char c) { return ((c == '0') ? '1' : '0'); }
bool inver;
char Get(int i) {
  if (inver)
    return inv(a[i]);
  else
    return a[i];
}
int main() {
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> a;
    cin >> b;
    vector<int> ans;
    int ar = n - 1;
    inver = false;
    char af = a[0];
    for (int i = 0; i < n; ++i) {
      if (Get(ar) == b[n - 1 - i]) {
        if (inver)
          ar++;
        else
          ar--;
        continue;
      }
      if (af != b[n - 1 - i]) {
        ans.push_back(n - i);
        char tmp = Get(ar);
        if (inver) {
          ar += (n - 1 - i);
        } else {
          ar -= (n - 1 - i);
        }
        inver = !inver;
        if (inver) {
          ++ar;
        } else {
          --ar;
        }
        af = inv(tmp);
      } else {
        ans.push_back(1);
        ans.push_back(n - i);
        char tmp = Get(ar);
        if (inver) {
          ar += (n - 1 - i);
        } else {
          ar -= (n - 1 - i);
        }
        inver = !inver;
        if (inver) {
          ++ar;
        } else {
          --ar;
        }
        af = inv(tmp);
      }
    }
    cout << (int)ans.size() << " ";
    for (int pre : ans) cout << pre << " ";
    cout << endl;
  }
}
