#include <bits/stdc++.h>
using namespace std;
template <class T, class V>
ostream& operator<<(ostream& s, pair<T, V> a) {
  s << a.first << ' ' << a.second;
  return s;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  long long int T = 1;
  cin >> T;
  for (long long int qq = 1; qq <= T; qq++) {
    long long int n;
    string a, b;
    cin >> n >> a >> b;
    vector<long long int> ans;
    long long int f = 0, l = n - 1, r = 0;
    for (int i = n - 1; i >= 0; i--) {
      if (b[i] - '0' != ((a[l] - '0') ^ f)) {
        if (a[l] != a[r]) a[r] = (a[r] - '0') ^ 1 + '0', ans.push_back(1);
        f ^= 1;
        ans.push_back(i + 1);
        swap(l, r);
      }
      if (l > r)
        l--;
      else
        l++;
    }
    cout << ans.size();
    for (auto x : ans) cout << ' ' << x;
    cout << endl;
  }
}
