#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 5;
int t;
int n;
string a, b;
int op[N];
int opb[N];
int bp = 0;
int ans = 0;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> n;
    ans = 0;
    cin >> a;
    cin >> b;
    if (a == b) {
      cout << 0 << endl;
      continue;
    }
    char st = a[0];
    for (int i = 1; i < n; i++) {
      if (a[i] != st) {
        op[++ans] = i;
        st = a[i];
      }
    }
    if (a[n - 1] == '0') op[++ans] = n;
    st = b[0];
    bp = 0;
    for (int i = 1; i < n; i++) {
      if (b[i] != st) {
        opb[++bp] = i;
        st = b[i];
      }
    }
    if (b[n - 1] == '0') opb[++bp] = n;
    cout << ans + bp;
    for (int i = 1; i <= ans; i++) cout << " " << op[i];
    for (int i = bp; i >= 1; i--) cout << " " << opb[i];
    cout << endl;
  }
  return 0;
}
