#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
const double eps = 1e-7;
const int maxn = 1e5 + 9;
const double pi = acos(-1.0);
const int inf = 2e9;
const long long mod = 1000000000;
char op[maxn], pq[maxn];
int io[2 * maxn];
char ui[maxn];
void flip(int pos) {
  for (int i = 0; i <= pos; ++i) {
    if (op[i] == '0')
      ui[i] = '1';
    else
      ui[i] = '0';
  }
  for (int i = 0; i <= pos; ++i) op[i] = ui[pos - i];
}
int main() {
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    int n, num = 0;
    cin >> n;
    cin >> op >> pq;
    for (int i = n - 1; i >= 0; --i) {
      if (op[i] == pq[i]) continue;
      if (op[0] != op[i]) {
        io[num++] = 1;
        flip(0);
      }
      flip(i);
      io[num++] = i + 1;
    }
    cout << num << " ";
    for (int i = 0; i < num; ++i) cout << io[i] << " ";
    cout << "\n";
  }
  return 0;
}
