#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ull = unsigned long long;
using ll = long long;
using ld = long double;
const long long brad = 1e9 + 7;
const long long maxn = 2e5;
const string alphabet = "abcdefghijklmnopqrstuvwxyz";
struct Group {
  long long a, b, c;
};
void foo(vector<long long> a, vector<long long> b, long long n) {
  vector<long long> r;
  long long lo, hi, last;
  lo = 0;
  hi = last = n - 1;
  while (1) {
    while (last >= 0) {
      if (a[hi] != b[last]) break;
      hi--;
      last--;
    }
    if (last < 0) break;
    if (a[lo] == b[last]) r.push_back(1);
    lo++;
    r.push_back(last + 1);
    last--;
    while (last >= 0) {
      if (a[lo] ^ 1 != b[last]) break;
      lo++;
      last--;
    }
    if (last < 0) break;
    if (a[hi] ^ 1 == b[last]) r.push_back(1);
    hi--;
    r.push_back(last + 1);
    last--;
  }
  cout << r.size() << " ";
  for (auto i : r) cout << i << " ";
  cout << "\n";
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t, n, u, v, r, x, y;
  bool f;
  cin >> t;
  while (t--) {
    string s, p;
    vector<long long> a, b;
    cin >> n >> s >> p;
    for (long long i = 0; i < n; i++) {
      a.push_back(s[i] - '0');
      b.push_back(p[i] - '0');
    }
    foo(a, b, n);
  }
  return 0;
}
