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

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

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

b = A("b")
c = B("c")
h = C("h")
f = A("f")

b.q = h
b.v = c
c.t = f
h.t = c
f.q = h
f.v = c
assert f.v.t.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: C = None
        self.v: B = None
        self.txt = txt

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

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

b = A("b")
c = B("c")
h = C("h")
f = A("f")

b.q = h
b.v = c
c.t = f
h.t = c
f.q = h
f.v = c
assert f.v.t.v.txt == "c"