#include <bits/stdc++.h>
using namespace std;
int t, n;
string a, b;
int main() {
  cin >> t;
  while (t--) {
    cin >> n >> a >> b;
    vector<int> v, v1;
    v.clear();
    a += '0', b += '0';
    for (int i = 1; i <= n; i++) {
      if (a[i] != a[i - 1]) v.push_back(i);
      if (b[i] != b[i - 1]) v1.push_back(i);
    }
    v.insert(v.end(), v1.rbegin(), v1.rend());
    cout << v.size() << " ";
    for (int i : v) cout << i << " ";
    cout << endl;
  }
}
