#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
long long posx[] = {1, -1, 0, 0};
long long posy[] = {0, 0, 1, -1};
void solve() {
  long long n, i, j, k;
  string a, b;
  cin >> n >> a >> b;
  vector<long long> v;
  int x1 = 0, x2 = n - 1;
  bool f = 0;
  for (i = n - 1; i >= 0; i--) {
    if (f == 0) {
      if (a[x1] == b[i]) {
        v.push_back(1);
      }
      v.push_back(x2 - x1 + 1);
      x1++;
      f = 1;
    } else {
      if (a[x2] != b[i]) v.push_back(1);
      v.push_back(x2 - x1 + 1);
      x2--;
      f = 0;
    }
  }
  cout << v.size() << " ";
  for (auto x : v) cout << x << " ";
  cout << '\n';
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
