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

class B:
    def __init__(self, txt: str):
        self.z: A = None
        self.y: A = None
        self.txt = txt

f = A("f")
h = B("h")
m = A("m")
l = A("l")
d = B("d")
g = B("g")
b = A("b")
j = B("j")
e = B("e")

f.q = l
f.r = b
h.z = m
h.y = f
m.q = l
m.r = f
l.q = b
l.r = b
d.z = f
d.y = b
g.z = l
g.y = l
b.q = l
b.r = f
j.z = l
j.y = b
e.z = b
e.y = l
assert j.z.r.r.r.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.r: A = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.z: A = None
        self.y: A = None
        self.txt = txt

f = A("f")
h = B("h")
m = A("m")
l = A("l")
d = B("d")
g = B("g")
b = A("b")
j = B("j")
e = B("e")

f.q = l
f.r = b
h.z = m
h.y = f
m.q = l
m.r = f
l.q = b
l.r = b
d.z = f
d.y = b
g.z = l
g.y = l
b.q = l
b.r = f
j.z = l
j.y = b
e.z = b
e.y = l
assert j.z.r.r.r.q.q.txt == "b"