#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    vector<int> ans;
    int pos = n - 1;
    while (pos >= 0) {
      while (pos >= 0 && b[pos] == a[pos]) {
        pos--;
      }
      if (pos < 0) break;
      if (a[0] != b[pos]) {
        ans.push_back(pos + 1);
        string c;
        for (int i = 0; i <= pos; i++) {
          c += (a[pos - i] == '0' ? '1' : '0');
        }
        for (int i = 0; i <= pos; i++) {
          a[i] = c[i];
        }
      } else {
        ans.push_back(1);
        a[0] = (a[0] == '0' ? '1' : '0');
        ans.push_back(pos + 1);
        string c;
        for (int i = 0; i <= pos; i++) {
          c += (a[pos - i] == '0' ? '1' : '0');
        }
        for (int i = 0; i <= pos; i++) {
          a[i] = c[i];
        }
      }
      pos--;
    }
    cout << ans.size() << " ";
    if (ans.size() > 0)
      for (int x : ans) cout << x << " ";
    cout << "\n";
  }
  return 0;
}
