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

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

i = A("i")
f = B("f")
a = A("a")
m = B("m")

i.q = f
f.w = m
a.q = f
m.w = f
assert a.q.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

i = A("i")
f = B("f")
a = A("a")
m = B("m")

i.q = f
f.w = m
a.q = f
m.w = f
assert a.q.w.w.w.txt == "m"