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

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

d = A("d")
h = B("h")
i = B("i")
b = A("b")

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

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

d = A("d")
h = B("h")
i = B("i")
b = A("b")

d.t = b
h.v = i
h.q = i
i.v = h
i.q = h
b.t = d
assert b.t.t.t.t.txt == "b"