#include <bits/stdc++.h>
using namespace std;
void fun(string a, vector<int> &ans) {
  int cnt1 = 0, cnt0 = 0;
  int n = a.length();
  for (int i = 0; i < n; i++) {
    if (a[i] == '1')
      cnt1++;
    else
      cnt0++;
  }
  if (cnt1 > cnt0) {
    ans.push_back(n);
    string tm = a;
    for (int i = 0; i < n; i++) {
      a[i] = (1 - (tm[n - 1 - i] - '0')) + '0';
    }
  }
  if (a[0] == '1') {
    ans.push_back(1);
    a[0] = '0';
  }
  for (int i = 1; i < n; i++) {
    if (a[i] == '1') {
      ans.push_back(i);
      ans.push_back(i + 1);
    }
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<int> ans;
    fun(a, ans);
    vector<int> ans2;
    fun(b, ans2);
    reverse(ans2.begin(), ans2.end());
    for (int i = 0; i < ans2.size(); i++) {
      ans.push_back(ans2[i]);
    }
    cout << ans.size() << " ";
    for (int i = 0; i < ans.size(); i++) {
      cout << ans[i] << " ";
    }
    cout << endl;
  }
}
