#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 9;
long long int mod = 1e9 + 7;
vector<int> turnToZero(string s) {
  vector<int> t;
  for (int x = 0; x < s.size() - 1; x++) {
    if (s[x] != s[x + 1]) t.push_back(x + 1);
  }
  if (s[s.size() - 1] == '1') t.push_back(s.size());
  return t;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    vector<int> res;
    int n;
    string a, b;
    cin >> n >> a >> b;
    for (int x : turnToZero(a)) res.push_back(x);
    vector<int> rev = turnToZero(b);
    reverse(rev.begin(), rev.end());
    for (int x : rev) res.push_back(x);
    cout << res.size() << endl;
    for (auto x : res) cout << x << " ";
    cout << endl;
  }
}
