#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
void solve() {
  int n;
  scanf("%d", &n);
  char a[100005], b[100005];
  scanf("%s %s", a, b);
  vector<int> v;
  int cnt = 0;
  int l = 0, r = n - 1;
  for (int i = n - 1; i >= 0; i--) {
    if (cnt & 1) {
      if (b[i] != a[r]) {
        v.push_back(1);
      }
      v.push_back(i + 1);
      r--;
    } else {
      if (b[i] == a[l]) {
        v.push_back(1);
      }
      v.push_back(i + 1);
      l++;
    }
    cnt++;
  }
  printf("%d\n", v.size());
  for (auto it : v) {
    printf("%d ", it);
  }
  printf("\n");
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
}
