#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}
inline long long lread() {
  long long s = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    s = s * 10 + ch - '0';
    ch = getchar();
  }
  return s * f;
}
string s1, s2;
vector<int> v1, v2;
int main() {
  cin.sync_with_stdio(false);
  int T;
  cin >> T;
  while (T--) {
    v1.clear();
    v2.clear();
    int n;
    cin >> n;
    cin >> s1 >> s2;
    s1.push_back('0');
    s2.push_back('0');
    for (register int i = (1); i <= (n); i++) {
      if (s1[i] != s1[i - 1]) v1.push_back(i);
      if (s2[i] != s2[i - 1]) v2.push_back(i);
    }
    cout << v1.size() + v2.size();
    for (auto val : v1) cout << " " << val;
    reverse(v2.begin(), v2.end());
    for (auto val : v2) cout << " " << val;
    cout << endl;
  }
  return 0;
}
