#include <bits/stdc++.h>
using namespace std;
int t, n;
string a, b;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n >> a >> b;
    bool flip = false;
    int idx = 0;
    vector<int> ops;
    for (int i = n - 1; i >= 0; i--) {
      if (flip ^ (a[idx] == b[i])) {
        ops.push_back(1);
      }
      ops.push_back(i + 1);
      if (flip)
        idx -= i;
      else
        idx += i;
      flip = !flip;
    }
    cout << ops.size() << ' ';
    for (int x : ops) {
      cout << x << ' ';
    }
    cout << '\n';
  }
}
