#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a;
    cin >> b;
    vector<int> ans;
    for (int i = 0; i < n; i++) {
      if (i + 1 < n && a[i] != a[i + 1])
        ans.push_back(i + 1);
      else if (i + 1 == n && a[i] == '1')
        ans.push_back(n);
    }
    int cur = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (b[i] - '0' != cur) {
        ans.push_back(i + 1);
        cur ^= 1;
      }
    }
    cout << ans.size() << ' ';
    for (int x : ans) cout << x << ' ';
    cout << endl;
  }
  return 0;
}
