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

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

j = A("j")
a = B("a")
m = B("m")
c = A("c")
f = B("f")
b = B("b")

j.y = a
j.q = a
a.t = f
a.r = m
m.t = b
m.r = f
c.y = m
c.q = a
f.t = m
f.r = m
b.t = f
b.r = f
assert c.y.r.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.q: B = None
        self.txt = txt

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

j = A("j")
a = B("a")
m = B("m")
c = A("c")
f = B("f")
b = B("b")

j.y = a
j.q = a
a.t = f
a.r = m
m.t = b
m.r = f
c.y = m
c.q = a
f.t = m
f.r = m
b.t = f
b.r = f
assert c.y.r.t.t.txt == "b"