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

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

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

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

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

e.u = m
e.r = i
g.z = c
g.q = c
g.x = i
i.q = m
i.s = d
i.x = g
d.s = i
n.s = i
m.u = e
m.r = i
c.q = e
c.s = d
c.x = g
assert n.s.x.z.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.r: C = None
        self.txt = txt

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

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

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

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

e.u = m
e.r = i
g.z = c
g.q = c
g.x = i
i.q = m
i.s = d
i.x = g
d.s = i
n.s = i
m.u = e
m.r = i
c.q = e
c.s = d
c.x = g
assert n.s.x.z.txt == "c"