#include <bits/stdc++.h>
using namespace std;
int t, n;
string a, b, ra;
bool rvrs = 0;
queue<int> q;
int main() {
  cin >> t;
  while (t--) {
    rvrs = 0;
    cin >> n >> a >> b;
    ra = a;
    reverse(ra.begin(), ra.end());
    for (int i = 0; i < ra.size(); i++) {
      if (ra[i] == '0')
        ra[i] = '1';
      else
        ra[i] = '0';
    }
    for (int i = n - 1; i >= 0; i--) {
      if (rvrs) {
        if (ra[0] == b[i]) q.push(1);
        q.push(i + 1);
        ra.erase(ra.begin());
      } else {
        if (a[0] == b[i]) q.push(1);
        q.push(i + 1);
        a.erase(a.begin());
      }
      rvrs = !rvrs;
    }
    cout << q.size() << " ";
    while (!q.empty()) {
      cout << q.front() << " ";
      q.pop();
    }
    cout << endl;
  }
  return 0;
}
