#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ;
  int t;
  cin >> t;
  while (t-- > 0) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<int> ans, ans1;
    char c, d;
    int f = 0, f1 = 0;
    for (int i = 0; i < n - 1; i++) {
      if (a[i] == a[i + 1]) {
        continue;
      } else {
        f = 1;
        c = a[i + 1];
        ans.push_back(i + 1);
      }
    }
    for (int i = 0; i < n - 1; i++) {
      if (b[i] == b[i + 1]) {
        continue;
      } else {
        f1 = 1;
        d = b[i + 1];
        ans1.push_back(i + 1);
      }
    }
    if (f == 0) {
      c = a[0];
    }
    if (f1 == 0) {
      d = b[0];
    }
    if (c != d) {
      ans.push_back(n);
    }
    for (int i = ans1.size() - 1; i >= 0; i--) {
      ans.push_back(ans1[i]);
    }
    cout << ans.size() << " ";
    for (int i = 0; i < ans.size(); i++) {
      cout << ans[i] << " ";
    }
    cout << endl;
  }
  return 0;
}
