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

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

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

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

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

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

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

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

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

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

e.q = m
e.v = g
g.y = m
g.p = m
c.u = m
c.q = e
m.w = c
m.z = g
m.q = g
assert g.y.w.q.txt == "e"