#include <bits/stdc++.h>
using namespace std;
int value(char ch, int flip) {
  int x = ch - '0';
  if (flip == 0)
    return x;
  else
    return 1 - x;
}
void update(int& flip, int& first, int& last) {
  int tmp = last;
  last = first + (last > first ? 1 : -1);
  first = tmp;
  flip = (flip + 1) % 2;
}
vector<int> convert(int n, string a, string b) {
  if (n == 1) {
    if (a[0] != b[0]) {
      return vector<int>{1};
    } else
      return {};
  }
  vector<int> res;
  int first = 0, last = n - 1, flip = 0;
  for (int i = n - 1; i >= 0; --i) {
    if ((i == 0) && value(a[last], flip) != int(b[i] - '0')) {
      res.push_back(1);
      continue;
    }
    if (value(a[last], flip) != int(b[i] - '0')) {
      if (1 - value(a[first], flip) != int(b[i] - '0')) {
        res.push_back(1);
      }
      res.push_back(i + 1);
      update(flip, first, last);
    } else
      last = last + (last > first ? -1 : +1);
  }
  return res;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a;
    cin >> b;
    vector<int> res = convert(n, a, b);
    cout << res.size() << " ";
    for (int i : res) cout << i << " ";
    cout << "\n";
  }
  return 0;
}
