#include <bits/stdc++.h>
using namespace std;
char s1[100005], s2[100005];
vector<int> vt;
int main() {
  int cases;
  scanf("%d", &cases);
  for (; cases; cases--) {
    int n;
    scanf("%d%s%s", &n, s1 + 1, s2 + 1);
    int l = 1, r = n;
    bool rev = 0, flip = 0;
    vt.clear();
    for (int i = n; i > 0; i--)
      if (!rev) {
        if ((s1[r] == s2[i]) ^ flip)
          r--;
        else if ((s1[l] != s2[i]) ^ flip) {
          vt.push_back(i);
          l++;
          rev ^= 1;
          flip ^= 1;
        } else {
          vt.push_back(1);
          vt.push_back(i);
          l++;
          rev ^= 1;
          flip ^= 1;
        }
      } else {
        if ((s1[l] == s2[i]) ^ flip)
          l++;
        else if ((s1[r] != s2[i]) ^ flip) {
          vt.push_back(i);
          r--;
          rev ^= 1;
          flip ^= 1;
        } else {
          vt.push_back(1);
          vt.push_back(i);
          r--;
          rev ^= 1;
          flip ^= 1;
        }
      }
    printf("%d ", (int)vt.size());
    for (int i = 0; i < vt.size(); i++) printf("%d ", vt[i]);
    printf("\n");
  }
  return 0;
}
