#include <bits/stdc++.h>
using namespace std;
int a[100005], b[100005];
void rr(int x) {
  for (int i = 1; i <= x; i++) a[x] ^= 1;
  reverse(a + 1, a + x + 1);
}
int main(int argc, char** argv) {
  int T = 1;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) scanf("%1d", &a[i]);
    for (int i = 1; i <= n; i++) scanf("%1d", &b[i]);
    int now = n;
    vector<int> ans;
    int l = 1, r = n, tmp = 0;
    while (now >= 1) {
      if (tmp == 0 && a[l] ^ 1 ^ tmp != b[now]) {
        ans.push_back(1);
      } else if (tmp == 1 && a[r] ^ 1 ^ tmp != b[now]) {
        ans.push_back(1);
      }
      if (!tmp)
        l++;
      else
        r--;
      tmp ^= 1;
      ans.push_back(now);
      now--;
    }
    printf("%d ", ans.size());
    for (int i = 0; i <= ans.size() - 1; i++) {
      printf("%d ", ans[i]);
    }
    printf("\n");
  }
  return 0;
}
