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

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

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

i = A("i")
b = B("b")
h = C("h")
d = B("d")
f = C("f")

i.o = f
i.y = h
b.o = d
b.t = d
b.y = i
h.y = f
h.q = i
d.o = b
d.t = b
d.y = i
f.y = h
f.q = i
assert h.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.o: C = None
        self.y: C = None
        self.txt = txt

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

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

i = A("i")
b = B("b")
h = C("h")
d = B("d")
f = C("f")

i.o = f
i.y = h
b.o = d
b.t = d
b.y = i
h.y = f
h.q = i
d.o = b
d.t = b
d.y = i
f.y = h
f.q = i
assert h.y.y.y.txt == "f"