#include <bits/stdc++.h>
using namespace std;
int t, n;
string a, b;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> t;
  while (t--) {
    cin >> n >> a >> b;
    deque<int> dq;
    for (char c : a) {
      dq.push_back(c - '0');
    }
    int idx = n - 1;
    bool inv = false;
    int p = 1;
    vector<int> v;
    for (int i = n - 1; i >= 0; i--) {
      int c = b[i] - '0';
      int fr = inv ? 1 - dq.front() : dq.front();
      int ba = inv ? 1 - dq.back() : dq.back();
      if (p == 1) {
        if (ba == c)
          dq.pop_back();
        else {
          if (fr == c) v.emplace_back(1);
          v.emplace_back(i + 1);
          inv = !inv;
          p *= -1;
          dq.pop_front();
        }
      } else {
        if (fr == c)
          dq.pop_front();
        else {
          if (ba == c) v.emplace_back(1);
          v.emplace_back(i + 1);
          inv = !inv;
          p *= -1;
          dq.pop_back();
        }
      }
    }
    cout << v.size();
    for (int x : v) {
      cout << ' ' << x;
    }
    cout << '\n';
  }
  return 0;
}
