#include <bits/stdc++.h>
using namespace std;
vector<int> V1, V2;
char s[200005], t[200005];
int main() {
  int n;
  int T;
  cin >> T;
  while (T--) {
    int n;
    V1.clear();
    V2.clear();
    scanf("%d", &n);
    scanf("%s%s", s + 1, t + 1);
    int len = strlen(s + 1);
    int st = 0;
    for (int i = n; i >= 1; i--) {
      if (s[i] == st + '0') V1.push_back(i), st ^= 1;
    }
    st = 0;
    for (int i = n; i >= 1; i--) {
      if (t[i] == st + '0') V2.push_back(i), st ^= 1;
    }
    reverse(V1.begin(), V1.end());
    printf("%d", V1.size() + V2.size());
    for (int i = 0; i < V1.size(); i++) printf(" %d", V1[i]);
    for (int i = 0; i < V2.size(); i++) printf(" %d", V2[i]);
    printf("\n");
  }
}
