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

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

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

l = A("l")
c = B("c")
f = C("f")
j = B("j")
m = B("m")
a = C("a")
i = B("i")
b = A("b")
g = B("g")
h = C("h")

l.q = h
c.r = g
c.v = i
f.t = h
f.r = c
j.r = m
j.v = m
m.r = g
m.v = j
a.t = h
a.r = c
i.r = c
i.v = m
b.q = h
g.r = c
g.v = j
h.t = a
h.r = c
assert f.r.r.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.txt = txt

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

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

l = A("l")
c = B("c")
f = C("f")
j = B("j")
m = B("m")
a = C("a")
i = B("i")
b = A("b")
g = B("g")
h = C("h")

l.q = h
c.r = g
c.v = i
f.t = h
f.r = c
j.r = m
j.v = m
m.r = g
m.v = j
a.t = h
a.r = c
i.r = c
i.v = m
b.q = h
g.r = c
g.v = j
h.t = a
h.r = c
assert f.r.r.v.v.txt == "m"