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

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

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

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

g = A("g")
m = B("m")
n = C("n")
a = D("a")

g.w = m
g.q = a
m.z = g
m.q = g
n.z = a
a.o = m
a.p = n
a.z = n
a.w = g
assert n.z.o.z.q.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.q: D = None
        self.txt = txt

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

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

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

g = A("g")
m = B("m")
n = C("n")
a = D("a")

g.w = m
g.q = a
m.z = g
m.q = g
n.z = a
a.o = m
a.p = n
a.z = n
a.w = g
assert n.z.o.z.q.txt == "a"