#include <bits/stdc++.h>
using namespace std;
const int maxl = 3e5 + 10;
int n, m, cas, k, cnt, tot;
int ans[maxl];
int a[maxl], b[maxl], tmp[maxl];
char s[maxl];
bool in[maxl];
inline void prework() {
  scanf("%d", &n);
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++) a[i] = s[i] - '0';
  scanf("%s", s + 1);
  for (int i = 1; i <= n; i++) b[i] = s[i] - '0';
}
inline void mainwork() {
  ans[0] = 0;
  for (int i = n; i >= 2; i--)
    if (a[i] != b[i]) {
      if (a[1] == b[i]) ans[++ans[0]] = 1, a[1] ^= 1;
      ans[++ans[0]] = i;
      for (int j = 1; j <= i; j++) tmp[j] = a[i - j + 1] ^ 1;
      for (int j = 1; j <= i; j++) a[j] = tmp[j];
    }
  if (a[1] != b[1]) ans[++ans[0]] = 1;
}
inline void print() {
  printf("%d ", ans[0]);
  for (int i = 1; i <= ans[0]; i++) printf("%d ", ans[i]);
  puts("");
}
int main() {
  int t = 1;
  scanf("%d", &t);
  for (cas = 1; cas <= t; cas++) {
    prework();
    mainwork();
    print();
  }
  return 0;
}
