#include <bits/stdc++.h>
using namespace std;
double tick() {
  static clock_t oldt, newt = clock();
  double diff = 1.0 * (newt - oldt) / CLOCKS_PER_SEC;
  oldt = newt;
  return diff;
}
inline long long int read() {
  long long int f = 1, x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long int fastExpo(long long int a, long long int n) {
  long long int res = 1;
  while (n) {
    if (n % 2) res = res * a;
    n /= 2;
    a = a * a;
  }
  return res;
}
int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};
vector<int> res;
int main() {
  int t = read();
  while (t--) {
    int n = read();
    string a, b;
    cin >> a >> b;
    int top = a[0] - '0';
    for (int i = 0; i < n; i++) {
      if ((a[i] - '0') != top) res.push_back(i), top = 1 - top;
    }
    for (int i = n - 1; i >= 0; i--) {
      if ((b[i] - '0') != top) res.push_back(i + 1), top = 1 - top;
    }
    cout << res.size() << " ";
    for (int j : res) cout << j << " ";
    cout << endl;
    res.clear();
  }
  cerr << "execution time is: " << tick() << "\n";
}
