#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--) {
    long long n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    bool rev = false;
    long long check = n - 1;
    long long last = 0;
    vector<long long> ans;
    for (long long i = n - 1; i >= 0; i--) {
      if (!rev) {
        if (b[i] != a[check]) {
          if (a[last] == b[i]) {
            ans.push_back(1);
          }
          ans.push_back(i + 1);
          rev = !rev;
          long long z = check;
          check = last + 1;
          last = z;
        } else {
          check--;
        }
      } else {
        if (b[i] == a[check]) {
          if (a[last] != b[i]) {
            ans.push_back(1);
          }
          ans.push_back(i + 1);
          rev = !rev;
          long long z = check;
          check = last - 1;
          last = z;
        } else {
          check++;
        }
      }
    }
    cout << ans.size() << " ";
    for (long long i = 0; i < ans.size(); i++) {
      cout << ans[i] << " ";
    }
    cout << "\n";
  }
  return 0;
}
