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

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

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

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

class E:
    def __init__(self, txt: str):
        self.t: D = None
        self.txt = txt

n = A("n")
f = B("f")
e = C("e")
l = D("l")
g = E("g")

n.u = l
n.r = g
f.z = l
f.x = n
e.p = f
l.z = e
g.t = l
assert l.z.p.z.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.r: E = None
        self.txt = txt

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

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

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

class E:
    def __init__(self, txt: str):
        self.t: D = None
        self.txt = txt

n = A("n")
f = B("f")
e = C("e")
l = D("l")
g = E("g")

n.u = l
n.r = g
f.z = l
f.x = n
e.p = f
l.z = e
g.t = l
assert l.z.p.z.txt == "l"