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

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

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

d = A("d")
g = B("g")
f = C("f")
m = B("m")
n = B("n")
e = A("e")
a = C("a")

d.y = g
g.v = n
f.x = m
f.o = e
f.q = n
m.v = n
n.v = g
e.y = g
a.x = g
a.o = d
a.q = n
assert m.v.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

d = A("d")
g = B("g")
f = C("f")
m = B("m")
n = B("n")
e = A("e")
a = C("a")

d.y = g
g.v = n
f.x = m
f.o = e
f.q = n
m.v = n
n.v = g
e.y = g
a.x = g
a.o = d
a.q = n
assert m.v.v.v.txt == "n"