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

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

e = A("e")
a = B("a")
f = B("f")

e.q = a
e.z = a
a.y = f
f.y = a
assert e.z.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.z: B = None
        self.txt = txt

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

e = A("e")
a = B("a")
f = B("f")

e.q = a
e.z = a
a.y = f
f.y = a
assert e.z.y.y.txt == "a"