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

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

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

class D:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

a = A("a")
m = B("m")
l = C("l")
b = D("b")

a.z = m
m.y = a
m.t = b
m.z = b
l.y = b
b.r = l
assert b.r.y.r.y.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.r: C = None
        self.txt = txt

a = A("a")
m = B("m")
l = C("l")
b = D("b")

a.z = m
m.y = a
m.t = b
m.z = b
l.y = b
b.r = l
assert b.r.y.r.y.txt == "b"