#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    int n;
    string a, b;
    cin >> n >> a >> b;
    int l = 0, r = n - 1, dir = 1, flip = 0;
    reverse(b.begin(), b.end());
    vector<int> ops;
    for (auto& c : b) {
      if (c != (a[r] ^ flip)) {
        if (l == r) {
          ops.push_back(1);
        } else {
          if (c == (a[l] ^ flip)) {
            ops.push_back(1);
          }
          ops.push_back(abs(r - l) + 1);
          l += dir;
          swap(l, r);
          dir *= -1;
          flip ^= 1;
        }
      } else {
        r -= dir;
      }
    }
    cout << ops.size() << ' ';
    for (auto& i : ops) {
      cout << i << ' ';
    }
    cout << '\n';
  }
}
