#include <bits/stdc++.h>
using namespace std;
const long long int NUM = 2e5 + 5;
int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int num_tests = 1;
  cin >> num_tests;
  while (num_tests-- > 0) {
    long long int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<long long int> ans;
    bool ok = 0;
    for (long long int i = 0; i < n; i++) {
      if (a[i] == '1') {
        long long int j = i;
        while (j < n and a[j] == '1') j++;
        if (i > 0) ans.push_back(i);
        ans.push_back(j);
        i = j;
      }
    }
    vector<long long int> revese;
    for (long long int i = 0; i < n; i++) {
      if (b[i] == '1') {
        long long int j = i;
        while (j < n and b[j] == '1') j++;
        if (i > 0) revese.push_back(i);
        revese.push_back(j);
        i = j;
      }
    }
    cout << ans.size() + revese.size() << " ";
    reverse(revese.begin(), revese.end());
    for (auto x : ans) cout << x << " ";
    for (auto x : revese) cout << x << " ";
    cout << "\n";
  }
}
