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