#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const long long mod = 1e9 + 7;
char aa[maxn], bb[maxn];
int a[maxn], b[maxn], ans[maxn];
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    int n;
    scanf("%d", &n);
    scanf("%s%s", aa + 1, bb + 1);
    for (int i = (1); i <= (n); i++) a[i] = aa[i] - '0', b[i] = bb[i] - '0';
    bool tag = 0;
    int l = 1, r = n, cnt = 0;
    for (int i = (n); i >= (1); i--) {
      if (!tag) {
        if (a[l] == b[i]) ans[++cnt] = 1;
        ans[++cnt] = i;
        l++;
      } else {
        if ((a[r] ^ 1) == b[i]) ans[++cnt] = 1;
        ans[++cnt] = i;
        r--;
      }
      tag ^= 1;
    }
    printf("%d ", cnt);
    for (int i = (1); i <= (cnt); i++) printf("%d ", ans[i]);
    puts("");
  }
}
