#include <bits/stdc++.h>
using namespace std;
inline long long maxi(long long &a, long long b) {
  if (b > a) {
    a = b;
    return 1;
  }
  return 0;
}
inline long long mini(long long &a, long long b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
inline long long maxi(long double &a, long double b) {
  if (b > a) {
    a = b;
    return 1;
  }
  return 0;
}
inline long long mini(long double &a, long double b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    string a, b;
    cin >> n >> a >> b;
    vector<long long> ans1, ans2;
    a += "0";
    b += "0";
    for (long long i = 1; i <= n; i++) {
      if (a[i] != a[i - 1]) {
        ans1.push_back(i);
      }
      if (b[i] != b[i - 1]) {
        ans2.push_back(i);
      }
    }
    for (long long i = (long long)ans2.size() - 1; i >= 0; i--) {
      ans1.push_back(ans2[i]);
    }
    cout << (long long)ans1.size() << "\n";
    for (auto now : ans1) {
      cout << now << ' ';
    }
    cout << "\n";
  }
}
