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

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

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

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

e = A("e")
m = B("m")
b = C("b")
h = D("h")

e.w = h
e.r = m
m.z = b
m.r = b
b.z = m
h.x = e
h.y = e
h.v = b
h.w = b
assert m.r.z.r.z.txt == "
class A:
    def __init__(self, txt: str):
        self.w: D = None
        self.r: B = None
        self.txt = txt

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

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

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

e = A("e")
m = B("m")
b = C("b")
h = D("h")

e.w = h
e.r = m
m.z = b
m.r = b
b.z = m
h.x = e
h.y = e
h.v = b
h.w = b
assert m.r.z.r.z.txt == "m"