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

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

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

k = A("k")
e = B("e")
m = C("m")
a = A("a")
b = C("b")
g = A("g")

k.y = g
e.p = g
e.o = m
m.q = e
m.v = e
a.y = k
b.q = e
b.v = e
g.y = a
assert m.q.p.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

k = A("k")
e = B("e")
m = C("m")
a = A("a")
b = C("b")
g = A("g")

k.y = g
e.p = g
e.o = m
m.q = e
m.v = e
a.y = k
b.q = e
b.v = e
g.y = a
assert m.q.p.y.y.y.txt == "g"