use std::io::*; fn main() { let mut s: String = String::new(); std::io::stdin().read_to_string(&mut s).ok(); let mut itr = s.trim().split_whitespace(); let t: usize = itr.next().unwrap().parse().unwrap(); let good: Vec = "good".chars().collect(); let problem: Vec = "problem".chars().collect(); let mut out = Vec::new(); for _ in 0..t { let s: Vec = itr.next().unwrap().chars().collect(); let n = s.len(); let mut ans = 1 << 30; for i in 0..n - 10 { for j in i + 4..n - 6 { let mut cnt = 0; for k in 0..4 { if good[k] != s[i + k] { cnt += 1; } } for k in 0..7 { if problem[k] != s[j + k] { cnt += 1; } } ans = std::cmp::min(ans, cnt); } } writeln!(out, "{}", ans).ok(); } stdout().write_all(&out).unwrap(); }