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

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

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

b.q = n
f.w = h
h.q = b
c.q = h
n.q = b
assert b.q.q.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: A = None
        self.txt = txt

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

b.q = n
f.w = h
h.q = b
c.q = h
n.q = b
assert b.q.q.q.q.q.txt == "n"