#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:10000000000")
#pragma GCC optimize("O3")
using namespace std;
const int MOD = 1000000007;
const int INF = 1000000007LL;
const long long INF2 = 1LL << 62LL;
const long double EPS = 1e-9;
const int SIZE = 200010;
mt19937 rng(time(0));
uniform_int_distribution<int> uid(-1000000000, 1000000000);
int flag, u[SIZE], d[SIZE], a[SIZE], n;
int rec(int i) {
  if (i == n - 1) return 1;
  if (u[i] == flag) return d[i];
  u[i] = flag;
  if (a[i] == 1) {
    return d[i] = !rec(i + 1);
  }
  return d[i] = 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt;
  cin >> tt;
  for (int rep_iter = 0; rep_iter < tt; ++rep_iter) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    int l = 0, r = n - 1, inv = 0;
    for (auto& i : a) i -= '0';
    for (auto& i : b) i -= '0';
    vector<int> ans;
    for (int len = n; len >= 1; --len) {
      if ((a[r] ^ inv) != b[len - 1]) {
        if ((a[l] ^ inv) == b[len - 1]) {
          ans.push_back(1);
          a[l] = !a[l];
        }
        ans.push_back(len);
        inv = !inv;
        swap(r, l);
      }
      if (r >= l)
        --r;
      else
        ++r;
    }
    cout << ans.size() << ' ';
    for (auto& i : ans) cout << i << ' ';
    cout << '\n';
  }
  return 0;
}
