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.txt = txt

b = A("b")
m = B("m")
h = A("h")

b.x = h
m.q = h
h.x = b
assert b.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.txt = txt

b = A("b")
m = B("m")
h = A("h")

b.x = h
m.q = h
h.x = b
assert b.x.x.x.txt == "h"