#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 228;
const long long INFLL = 1e18;
const long long MOD = 1e9 + 7;
const long double eps = 1e-6;
const long double eps2 = 1e-9;
const long long MOD2 = 998244353;
const long long dosz = 5e5;
const long long SZ = (1 << 18);
const long double PI = atan2l(0, -1);
void fast_io() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
void solve() {
  long long n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  vector<long long> ans;
  char cur = a[0];
  for (long long i = 1; i < n; i++) {
    if (a[i] != cur) {
      ans.push_back(i);
      cur = a[i];
    }
  }
  for (long long i = n - 1; i >= 0; i--) {
    if (cur != b[i]) {
      ans.push_back(i + 1);
      if (cur == '1')
        cur = '0';
      else
        cur = '1';
    }
  }
  cout << ans.size() << " ";
  for (long long i : ans) cout << i << " ";
  cout << endl;
}
signed main() {
  fast_io();
  srand(time(NULL));
  cout << fixed << setprecision(12);
  long long q = 1;
  cin >> q;
  while (q--) solve();
}
