#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int n;
string a, b;
vector<int> res;
void read() {
  cin >> n >> a >> b;
  res.clear();
}
int makeSame() {
  int it = 1;
  int cur = a[0] - '0';
  while (it < n) {
    if (a[it - 1] != a[it]) {
      res.push_back(it);
      cur = a[it] - '0';
    }
    ++it;
  }
  return cur;
}
void solve() {
  read();
  int st = makeSame();
  for (int i = n - 1; i >= 0; --i) {
    if (b[i] - '0' != st) {
      res.push_back(i + 1);
      st = !st;
    }
  }
  cout << res.size() << " ";
  for (int u : res) {
    cout << u << " ";
  }
  cout << "\n";
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int z = 1;
  cin >> z;
  while (z--) {
    solve();
  }
  return 0;
}
