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

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

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

a = A("a")
f = B("f")
e = C("e")
i = B("i")
h = C("h")

a.q = i
f.w = a
f.v = a
f.o = e
e.q = h
i.w = a
i.v = a
i.o = h
h.q = e
assert i.o.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.txt = txt

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

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

a = A("a")
f = B("f")
e = C("e")
i = B("i")
h = C("h")

a.q = i
f.w = a
f.v = a
f.o = e
e.q = h
i.w = a
i.v = a
i.o = h
h.q = e
assert i.o.q.q.txt == "h"