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

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

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

k = A("k")
d = B("d")
a = C("a")
b = C("b")
n = A("n")
j = B("j")

k.x = n
d.r = b
d.p = n
a.u = d
b.u = j
n.x = k
j.r = a
j.p = k
assert j.p.x.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.txt = txt

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

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

k = A("k")
d = B("d")
a = C("a")
b = C("b")
n = A("n")
j = B("j")

k.x = n
d.r = b
d.p = n
a.u = d
b.u = j
n.x = k
j.r = a
j.p = k
assert j.p.x.x.x.x.txt == "k"