#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;
    int right = n - 1;
    int i = n - 1;
    vector<int> v;
    while (i >= 0) {
      if (a[i] == b[i]) {
        i--;
        continue;
      } else if (a[0] == b[i]) {
        v.push_back(1);
        if (a[0] == '0')
          a[0] = '1';
        else
          a[0] = '0';
        v.push_back(i + 1);
        for (int j = 0; j <= i; j++) {
          if (a[j] == '0')
            a[j] = '1';
          else
            a[j] = '0';
        }
        int start = 0;
        int end = i;
        while (start <= end) {
          char t = a[start];
          a[start] = a[end];
          a[end] = t;
          start++;
          end--;
        }
      } else if (a[0] != b[i]) {
        v.push_back(i + 1);
        for (int j = 0; j <= i; j++) {
          if (a[j] == '0')
            a[j] = '1';
          else
            a[j] = '0';
        }
        int start = 0;
        int end = i;
        while (start <= end) {
          char t = a[start];
          a[start] = a[end];
          a[end] = t;
          start++;
          end--;
        }
      }
      i--;
    }
    cout << v.size() << " ";
    for (int k = 0; k < v.size(); k++) cout << v[k] << " ";
    cout << endl;
  }
}
