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

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

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

l = A("l")
f = B("f")
j = C("j")
d = A("d")
k = C("k")
h = C("h")
n = C("n")
c = B("c")
a = B("a")
g = C("g")

l.o = k
f.y = d
f.q = h
f.t = a
j.w = l
d.o = k
k.w = l
h.w = l
n.w = d
c.y = d
c.q = g
c.t = a
a.y = d
a.q = h
a.t = c
g.w = d
assert l.o.w.o.w.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.txt = txt

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

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

l = A("l")
f = B("f")
j = C("j")
d = A("d")
k = C("k")
h = C("h")
n = C("n")
c = B("c")
a = B("a")
g = C("g")

l.o = k
f.y = d
f.q = h
f.t = a
j.w = l
d.o = k
k.w = l
h.w = l
n.w = d
c.y = d
c.q = g
c.t = a
a.y = d
a.q = h
a.t = c
g.w = d
assert l.o.w.o.w.txt == "l"