#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e9;
string s, p, temp;
int l[200005], r[200005];
void process(int n) {
  for (int i = 1; i <= n; i++) {
    l[i] = i;
    r[i] = n - i + 1;
  }
}
void solve(int n) {
  int key = 0;
  vector<int> v;
  int x = 0, y = n - 1;
  for (int i = 0, j = n - 1; i < n, j >= 0; i++, j--) {
    if (i & 1) {
      if (s[y] == '0')
        s[y] = '1';
      else
        s[y] = '0';
      if (s[y] == p[j]) {
        v.push_back(1);
        v.push_back(j + 1);
      } else {
        v.push_back(j + 1);
      }
      y--;
    } else {
      if (s[x] == p[j]) {
        v.push_back(1);
        v.push_back(j + 1);
      } else {
        v.push_back(j + 1);
      }
      x++;
    }
  }
  cout << v.size();
  for (int i = 0; i < v.size(); i++) {
    cout << ' ' << v[i];
  }
  cout << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int t, n, i, j;
  cin >> t;
  while (t--) {
    cin >> n;
    cin >> s >> p;
    process(n);
    solve(n);
  }
  return 0;
}
