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

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

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

i = A("i")
f = B("f")
n = C("n")
d = A("d")
k = B("k")
m = C("m")

i.q = d
i.o = f
f.v = i
n.q = k
d.q = i
d.o = k
k.v = i
m.q = f
assert d.o.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: A = None
        self.o: B = None
        self.txt = txt

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

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

i = A("i")
f = B("f")
n = C("n")
d = A("d")
k = B("k")
m = C("m")

i.q = d
i.o = f
f.v = i
n.q = k
d.q = i
d.o = k
k.v = i
m.q = f
assert d.o.v.q.txt == "d"