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

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

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

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

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

k = A("k")
a = B("a")
e = C("e")
g = D("g")
j = E("j")
l = B("l")

k.u = g
a.u = k
a.y = k
e.x = g
g.r = a
j.p = l
l.u = k
l.y = k
assert a.y.u.r.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

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

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

k = A("k")
a = B("a")
e = C("e")
g = D("g")
j = E("j")
l = B("l")

k.u = g
a.u = k
a.y = k
e.x = g
g.r = a
j.p = l
l.u = k
l.y = k
assert a.y.u.r.txt == "a"