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

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

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

h = A("h")
i = B("i")
e = C("e")
b = A("b")

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

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

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

h = A("h")
i = B("i")
e = C("e")
b = A("b")

h.q = b
i.w = e
i.v = e
e.q = h
b.q = h
assert b.q.q.q.txt == "h"