#include <bits/stdc++.h>
using namespace std;
int main() {
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<long long> ans;
    for (long long i = n - 1; i >= 0; i--) {
      if (a[i] != b[i]) {
        if (a[0] == b[i]) {
          ans.push_back(1);
          a[0] = (a[0] == '0') ? '1' : '0';
        }
        ans.push_back(i + 1);
        string aux = a;
        for (long long j = 0; j <= i; j++) {
          char c = (a[j] == '0') ? '1' : '0';
          aux[i - j] = c;
        }
        a = aux;
      }
    }
    printf("%lu", ans.size());
    for (auto &x : ans) {
      printf(" %lld", x);
    }
    printf("\n");
  }
}
