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

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

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

n = A("n")
d = B("d")
f = C("f")
a = A("a")
c = C("c")
m = B("m")
i = C("i")
e = A("e")
l = C("l")
g = A("g")

n.t = i
d.x = m
d.p = c
d.w = e
f.x = i
f.t = c
f.r = n
a.t = l
c.x = f
c.t = i
c.r = a
m.x = d
m.p = f
m.w = g
i.x = f
i.t = c
i.r = e
e.t = i
l.x = c
l.t = i
l.r = n
g.t = l
assert f.r.t.r.t.r.t.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.txt = txt

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

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

n = A("n")
d = B("d")
f = C("f")
a = A("a")
c = C("c")
m = B("m")
i = C("i")
e = A("e")
l = C("l")
g = A("g")

n.t = i
d.x = m
d.p = c
d.w = e
f.x = i
f.t = c
f.r = n
a.t = l
c.x = f
c.t = i
c.r = a
m.x = d
m.p = f
m.w = g
i.x = f
i.t = c
i.r = e
e.t = i
l.x = c
l.t = i
l.r = n
g.t = l
assert f.r.t.r.t.r.t.txt == "i"