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

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

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

n = A("n")
g = B("g")
b = C("b")
l = A("l")
f = A("f")
e = C("e")
k = B("k")
a = A("a")

n.x = f
n.p = b
g.t = n
b.r = k
l.x = f
l.p = e
f.x = n
f.p = b
e.r = k
k.t = l
a.x = f
a.p = b
assert l.x.x.p.r.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.p: C = None
        self.txt = txt

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

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

n = A("n")
g = B("g")
b = C("b")
l = A("l")
f = A("f")
e = C("e")
k = B("k")
a = A("a")

n.x = f
n.p = b
g.t = n
b.r = k
l.x = f
l.p = e
f.x = n
f.p = b
e.r = k
k.t = l
a.x = f
a.p = b
assert l.x.x.p.r.t.x.txt == "f"