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

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

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

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

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

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

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

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

l.r = j
j.x = l
n.t = g
n.r = b
d.x = g
b.x = a
g.r = j
a.r = j
f.t = l
f.r = j
e.t = l
e.r = j
assert g.r.x.r.x.r.x.r.txt == "j"