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