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

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

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

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

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

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

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

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

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

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

e.p = m
e.s = c
m.y = g
m.q = c
c.y = e
c.z = e
c.t = g
g.v = m
assert g.v.y.v.y.txt == "g"