#include <bits/stdc++.h>
using namespace std;
int tc, n;
char A[100005], B[100005];
vector<int> ans;
int main() {
  scanf("%d", &tc);
  while (tc--) {
    scanf("%d", &n);
    scanf("%s", &A);
    scanf("%s", &B);
    ans.clear();
    int inv = 0;
    int l = 0, r = n - 1;
    for (int i = n - 1; i >= 0; i--) {
      if (!inv) {
        if (A[r] == B[i]) {
          r--;
          continue;
        }
        if (A[l] == B[i]) {
          ans.push_back(1);
          ans.push_back(i + 1);
          l++;
          inv ^= 1;
        } else {
          ans.push_back(i + 1);
          l++;
          inv ^= 1;
        }
      } else {
        if (A[l] != B[i]) {
          l++;
          continue;
        }
        if (A[r] != B[i]) {
          ans.push_back(1);
          ans.push_back(i + 1);
          r--;
          inv ^= 1;
        } else {
          ans.push_back(i + 1);
          r--;
          inv ^= 1;
        }
      }
    }
    if ((int)(ans.size()) > 2 * n) assert(1 == 2);
    printf("%d", (int)(ans.size()));
    for (int v : ans) {
      printf(" %d", v);
    }
    printf("\n");
  }
  return 0;
}
