#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    a += "0";
    b += "0";
    vector<int> ans;
    for (int i = 0; i < n; i++) {
      if (a[i] != a[i + 1]) ans.push_back(i);
    }
    for (int i = n - 1; i >= 0; i--) {
      if (b[i] != b[i + 1]) ans.push_back(i);
    }
    cout << ans.size() << " ";
    for (auto mk : ans) cout << mk + 1 << " ";
    cout << endl;
  }
  return 0;
}
