#include <bits/stdc++.h>
#pragma GCC optimize "O3"
using namespace std;
const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const int N = 1e5 + 5;
int n;
char a[N], b[N];
void solve() {
  cin >> n;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= n; i++) cin >> b[i];
  vector<int> ans;
  int l = 1, r = n;
  for (int i = n; i >= 1; i--) {
    if ((n - i) % 2 == 0) {
      if (a[l] == b[i]) ans.push_back(1);
      l++;
    } else {
      if (a[r] != b[i]) ans.push_back(1);
      r--;
    }
    ans.push_back(i);
  }
  cout << ((int)ans.size()) << ' ';
  for (auto &x : ans) cout << x << ' ';
  cout << '\n';
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int tt;
  cin >> tt;
  for (int te = 1; te <= tt; te++) {
    solve();
  }
  return 0;
}
