#include <bits/stdc++.h>
using namespace std;
string a, b;
void solve(string *a, int i) {
  string s = (*a).substr(0, i + 1);
  for (int j = 0; j < i + 1; j++) {
    if (s[j] == '0')
      s[j] = '1';
    else
      s[j] = '0';
  }
  for (int j = 0; j < i + 1; j++) {
    (*a)[i - j] = s[j];
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, q = 0;
    cin >> n;
    vector<int> v;
    cin >> a >> b;
    for (int i = n - 1; i > 0; i--) {
      if (a[i] != b[i]) {
        q++;
        if (a[0] == b[i]) {
          v.push_back(1);
          if (a[0] == '1')
            a[0] = '0';
          else
            a[0] = '1';
        }
        v.push_back(i + 1);
        solve(&a, i);
      }
    }
    if (a[0] != b[0]) {
      q++;
      v.push_back(1);
      if (a[0] == '1')
        a[0] = '0';
      else
        a[0] = '1';
    }
    if (q == 0)
      cout << 0;
    else {
      cout << v.size() << " ";
      for (int x : v) cout << x << " ";
    }
    cout << endl;
  }
  return 0;
}
