#include <bits/stdc++.h>
using namespace std;
char a[100009];
deque<int> v;
vector<int> w;
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    char c;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
      cin >> c;
      v.push_back(c);
    }
    for (int i = 0; i < n; i++) cin >> a[i];
    int x = 0;
    int op = 0;
    for (int i = n - 1; i > -1; i--) {
      x %= 2;
      op %= 2;
      char u;
      if (x)
        u = v.front();
      else
        u = v.back();
      if (op) u = '1' - u + '0';
      if (u == a[i]) {
        if (op)
          v.pop_front();
        else
          v.pop_back();
        continue;
      }
      if (x == 0) {
        if (v.front() == v.back()) {
          w.push_back(i);
          x++;
          op++;
        } else {
          w.push_back(0);
          char z = v[0];
          v.pop_front();
          v.push_front('1' - z + '0');
          w.push_back(i);
          x++;
          op++;
        }
      } else {
        if (v.front() == v.back()) {
          w.push_back(i);
          x++;
          op++;
        } else {
          w.push_back(0);
          char z = v[0];
          v.pop_back();
          v.push_back(1 - z + '0');
          w.push_back(i);
          x++;
          op++;
        }
      }
      op %= 2;
      if (op)
        v.pop_front();
      else
        v.pop_back();
    }
    cout << w.size() << " ";
    for (auto it : w) cout << it + 1 << " ";
    cout << endl;
    w.clear();
  }
}
