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

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

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

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

a = A("a")
l = B("l")
m = C("m")
b = D("b")
d = D("d")
k = A("k")

a.x = k
a.s = k
a.p = m
l.r = b
m.u = l
b.t = d
d.t = b
k.x = a
k.s = a
k.p = m
assert k.p.u.r.t.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.s: A = None
        self.p: C = None
        self.txt = txt

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

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

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

a = A("a")
l = B("l")
m = C("m")
b = D("b")
d = D("d")
k = A("k")

a.x = k
a.s = k
a.p = m
l.r = b
m.u = l
b.t = d
d.t = b
k.x = a
k.s = a
k.p = m
assert k.p.u.r.t.t.t.txt == "d"