#include <bits/stdc++.h>
using namespace std;
const double pi = 3.1415926535897932384626;
const long long int mod = 1e9 + 7;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int t;
  cin >> t;
  while (t--) {
    long long int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    a += '0';
    b += '0';
    vector<long long int> x, y;
    for (long long int i = 0; i < n; i++) {
      if (a[i + 1] != a[i]) x.push_back(i + 1);
      if (b[i + 1] != b[i]) y.push_back(i + 1);
    }
    cout << x.size() + y.size() << " ";
    for (auto i : x) cout << i << " ";
    reverse(y.begin(), y.end());
    for (auto i : y) cout << i << " ";
    cout << "\n";
  }
  return 0;
}
