#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  unsigned long long int a, b, n, m, t;
  cin >> t;
  while (t--) {
    cin >> n;
    vector<char> a(n), b(n);
    for (auto& it : a) {
      cin >> it;
    }
    for (auto& it : b) {
      cin >> it;
    }
    std::vector<int> ans;
    int real = 1;
    int oneindex = 0;
    int inrun = n - 1;
    for (int i = n - 1; i >= 0; i--) {
      if (a[inrun] == b[i] && real) {
        inrun--;
        continue;
      } else if (a[inrun] != b[i] && !real) {
        inrun++;
        continue;
      }
      if (a[inrun] != b[i] && real) {
        if (a[oneindex] == b[i]) {
          ans.push_back(0);
          real = 0;
          ans.push_back(i);
          swap(oneindex, inrun);
        } else if (a[oneindex] != b[i]) {
          real = 0;
          ans.push_back(i);
          swap(oneindex, inrun);
        }
        inrun++;
      } else if (a[inrun] == b[i] && !real) {
        if (a[oneindex] != b[i]) {
          ans.push_back(0);
          real = 1;
          ans.push_back(i);
          swap(oneindex, inrun);
        } else {
          real = 1;
          ans.push_back(i);
          swap(oneindex, inrun);
        }
        inrun--;
      }
    }
    cout << ans.size() << " ";
    for (auto it : ans) cout << it + 1 << " ";
    cout << endl;
  }
  return 0;
}
