#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0), cout.tie(0);
  long long int t, n, k, i, j, m;
  cin >> t;
  while (t--) {
    vector<long long int> v;
    string a, b, s;
    long long int c = 0, d = 0;
    cin >> n >> a >> b;
    s += a[0];
    for (i = a.size() - 1; i >= 0; i--) {
      if (i == 0) {
        if (s[0] != b[i]) {
          v.push_back(1);
        }
      } else {
        if (s[0] == b[i]) {
          v.push_back(1);
          v.push_back(i + 1);
        } else {
          v.push_back(i + 1);
          if (a[i] == '0')
            s[0] = '1';
          else
            s[0] = '0';
        }
      }
      if (d % 2 == 0) {
        if (a[n - 1 - c] == '0')
          s[0] = '1';
        else
          s[0] = '0';
        c++;
      } else {
        s[0] = a[c];
      }
      d++;
    }
    if (v.size() == 0) {
      cout << 0 << endl;
      continue;
    }
    cout << v.size() << " ";
    for (i = 0; i < v.size() - 1; i++) {
      cout << v[i] << " ";
    }
    cout << v[i] << endl;
  }
  return 0;
}
