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

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

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

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

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

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

b.x = h
c.q = b
c.v = b
f.x = n
h.x = f
n.x = b
assert h.x.x.x.txt == "b"