class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.p: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: A = None
        self.r: A = None
        self.txt = txt

b = A("b")
j = B("j")
d = B("d")
f = B("f")
n = A("n")
k = B("k")
g = B("g")
h = A("h")

b.q = k
b.p = d
j.s = n
j.r = n
d.s = b
d.r = n
f.s = n
f.r = h
n.q = d
n.p = f
k.s = n
k.r = n
g.s = b
g.r = n
h.q = k
h.p = j
assert k.s.q.s.p.r.q.r.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.p: B = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.s: A = None
        self.r: A = None
        self.txt = txt

b = A("b")
j = B("j")
d = B("d")
f = B("f")
n = A("n")
k = B("k")
g = B("g")
h = A("h")

b.q = k
b.p = d
j.s = n
j.r = n
d.s = b
d.r = n
f.s = n
f.r = h
n.q = d
n.p = f
k.s = n
k.r = n
g.s = b
g.r = n
h.q = k
h.p = j
assert k.s.q.s.p.r.q.r.q.txt == "d"