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

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

b = A("b")
d = B("d")
k = A("k")
c = A("c")
h = B("h")

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

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

b = A("b")
d = B("d")
k = A("k")
c = A("c")
h = B("h")

b.v = k
d.q = b
k.v = b
c.v = k
h.q = k
assert d.q.v.v.v.v.txt == "b"