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