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

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

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

h = A("h")
l = B("l")
f = C("f")
d = A("d")
j = A("j")
e = A("e")
n = A("n")
m = B("m")
a = A("a")

h.t = f
h.r = e
l.x = f
l.v = m
f.x = n
d.t = f
d.r = a
j.t = f
j.r = n
e.t = f
e.r = a
n.t = f
n.r = h
m.x = f
m.v = l
a.t = f
a.r = h
assert h.r.r.t.x.txt == "
class A:
    def __init__(self, txt: str):
        self.t: C = None
        self.r: A = None
        self.txt = txt

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

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

h = A("h")
l = B("l")
f = C("f")
d = A("d")
j = A("j")
e = A("e")
n = A("n")
m = B("m")
a = A("a")

h.t = f
h.r = e
l.x = f
l.v = m
f.x = n
d.t = f
d.r = a
j.t = f
j.r = n
e.t = f
e.r = a
n.t = f
n.r = h
m.x = f
m.v = l
a.t = f
a.r = h
assert h.r.r.t.x.txt == "n"