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

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

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

class D:
    def __init__(self, txt: str):
        self.q: B = None
        self.v: C = None
        self.txt = txt

m = A("m")
e = B("e")
g = C("g")
d = D("d")

m.u = g
m.y = e
e.p = d
e.z = d
g.z = m
g.t = m
d.q = e
d.v = g
assert g.z.y.z.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.y: B = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.q: B = None
        self.v: C = None
        self.txt = txt

m = A("m")
e = B("e")
g = C("g")
d = D("d")

m.u = g
m.y = e
e.p = d
e.z = d
g.z = m
g.t = m
d.q = e
d.v = g
assert g.z.y.z.txt == "d"