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

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

k = A("k")
h = B("h")
b = B("b")
e = A("e")

k.q = e
h.v = b
h.x = k
b.v = h
b.x = k
e.q = k
assert e.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.v: B = None
        self.x: A = None
        self.txt = txt

k = A("k")
h = B("h")
b = B("b")
e = A("e")

k.q = e
h.v = b
h.x = k
b.v = h
b.x = k
e.q = k
assert e.q.q.q.txt == "k"