#include <bits/stdc++.h>
using namespace std;
char tt1[1000005];
char tt2[1000005];
int a[1000005];
int b[1000005];
vector<int> ans;
int main() {
  int T, ok, now, l, r, N, i;
  scanf("%d", &T);
  while (T--) {
    ans.clear();
    scanf("%d %s %s", &N, tt1, tt2);
    l = 0;
    r = N - 1;
    now = 0;
    for (i = 0; i < N; i++) {
      a[i] = tt1[i] - '0';
      b[i] = tt2[i] - '0';
    }
    for (i = N - 1; i >= 0; i--) {
      if ((now ^ a[r]) == b[i]) {
        if (l < r)
          r--;
        else
          r++;
      } else {
        if ((now ^ a[l]) != b[i]) {
          ans.push_back(i);
          now = 1 - now;
          swap(l, r);
          if (l < r)
            r--;
          else
            r++;
        } else {
          ans.push_back(0);
          ans.push_back(i);
          now = 1 - now;
          swap(l, r);
          if (l < r)
            r--;
          else
            r++;
        }
      }
    }
    printf("%d ", ans.size());
    for (auto i : ans) printf("%d ", i + 1);
    printf("\n");
  }
  return 0;
}
