#include <bits/stdc++.h>
using namespace std;
int n;
char _a[200020], _b[200020];
int ans[200020 << 2], a[200020], b[200020], cs = 0;
bool ok = 0;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d", &n);
    scanf("%s%s", _a + 1, _b + 1);
    for (register int i = 1; i <= n; i++)
      a[i] = _a[i] - '0', b[i] = _b[i] - '0';
    int l = 1, r = n, ok = 0;
    for (register int i = n; i >= 1; i--) {
      int x;
      if (l < r)
        x = a[i - 1 + l];
      else
        x = a[l - i + 1];
      x ^= ok;
      if (x == b[i]) {
        if (l < r)
          r--;
        else
          r++;
        continue;
      }
      x = a[l] ^ ok;
      if ((x ^ 1) != b[i]) {
        ans[++cs] = 1;
        a[l] ^= 1;
      }
      ans[++cs] = i;
      swap(l, r);
      ok ^= 1;
      if (l < r)
        r--;
      else
        r++;
    }
    printf("%d", cs);
    for (register int i = 1; i <= cs; i++) printf(" %d", ans[i]);
    printf("\n");
    cs = 0;
  }
  return 0;
}
