#include <bits/stdc++.h>
using namespace std;
bool sortbysecond(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second > b.second);
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
template <typename T>
string NumberTostring(T Number) {
  ostringstream second;
  second << Number;
  return second.str();
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long t;
  cin >> t;
  while (t--) {
    long long n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<long long> vec;
    for (int i = n - 1; i >= 0; i--) {
      if (a[i] != b[i]) {
        if (a[0] == b[i]) {
          vec.push_back(1);
          a[0] = '0' + !(a[0] - '0');
        }
        reverse(a.begin(), a.begin() + i + 1);
        for (int j = 0; j <= i; j++) {
          a[j] = '0' + !(a[j] - '0');
        }
        vec.push_back(i + 1);
      }
    }
    cout << vec.size() << " ";
    for (long long o = 0; o < vec.size(); o++) cout << vec[o] << " ";
    cout << "\n";
  }
  return 0;
}
