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

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

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

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

m = A("m")
f = B("f")
n = C("n")
g = D("g")
j = C("j")

m.u = j
m.x = f
f.s = g
n.z = f
n.t = j
g.q = f
g.o = n
g.r = n
g.v = m
j.z = f
j.t = n
assert n.z.s.q.s.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.x: B = None
        self.txt = txt

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

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

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

m = A("m")
f = B("f")
n = C("n")
g = D("g")
j = C("j")

m.u = j
m.x = f
f.s = g
n.z = f
n.t = j
g.q = f
g.o = n
g.r = n
g.v = m
j.z = f
j.t = n
assert n.z.s.q.s.q.txt == "f"