#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int n;
string s1, s2;
vector<int> ans;
inline int getint() {
  int num = 0, bj = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == EOF) return EOF;
    bj = (c == '-' || bj == -1) ? -1 : 1, c = getchar();
  }
  while (c >= '0' && c <= '9') num = num * 10 + c - '0', c = getchar();
  return num * bj;
}
void init() {}
void solve() {
  int T;
  cin >> T;
  while (T--) {
    ans.clear();
    n = getint();
    cin >> s1 >> s2;
    string s = s1 + "0";
    for (int i = 0; i < s.length() - 1; ++i) {
      if (s[i] != s[i + 1]) {
        ans.push_back(i + 1);
      }
    }
    s = s2 + "0";
    for (int i = s.length() - 2; i >= 0; --i) {
      if (s[i] != s[i + 1]) {
        ans.push_back(i + 1);
      }
    }
    cout << ans.size();
    for (int item : ans) {
      cout << " " << item;
    }
    cout << endl;
  }
}
int main() {
  init();
  solve();
}
