#include <bits/stdc++.h>
using namespace std;
long double pi = 2 * acos(0.0);
const long long mod = 1e9 + 7;
void solve() {
  long long n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  vector<long long> ans, ans1;
  for (long long i = 0; i < n; i++) {
    if (a[i] == '1') {
      long long j = i++;
      while (i < n && a[i] == '1') i++;
      if (j == 0)
        ans.emplace_back(i);
      else {
        ans.emplace_back(j);
        ans.emplace_back(i);
      }
    }
  }
  for (long long i = 0; i < n; i++) {
    if (b[i] == '1') {
      long long j = i++;
      while (i < n && b[i] == '1') i++;
      if (j == 0)
        ans1.emplace_back(i);
      else {
        ans1.emplace_back(j);
        ans1.emplace_back(i);
      }
    }
  }
  reverse(ans1.begin(), ans1.end());
  cout << ans.size() + ans1.size() << " ";
  for (auto i : ans) cout << i << " ";
  for (auto i : ans1) cout << i << " ";
  cout << "\n";
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(nullptr);
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
