#include <bits/stdc++.h>
using namespace std;
char a[100005], b[100005];
int ans[200009];
int main() {
  int t;
  cin >> t;
  while (t--) {
    int cnt = 0;
    int n;
    cin >> n;
    for (int j = 1; j <= n; j++) {
      cin >> a[j];
    }
    for (int j = 1; j <= n; j++) {
      cin >> b[j];
    }
    for (int j = 1; j <= n - 1; j++) {
      if (a[j] == a[j + 1]) {
        continue;
      }
      if (a[j] != a[j + 1]) {
        ans[cnt++] = j;
      }
    }
    char c = a[n];
    for (int j = n; j >= 1; j--) {
      if (b[j] == c) continue;
      if (b[j] != c) {
        if (c == '1') {
          c = '0';
        } else {
          c = '1';
        }
        ans[cnt++] = j;
      }
    }
    cout << cnt << " ";
    for (int k = 0; k < cnt; k++) {
      cout << ans[k] << " ";
    }
    cout << "\n";
  }
  return 0;
}
