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

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

c = A("c")
h = B("h")
m = B("m")
n = A("n")
a = A("a")

c.v = n
h.q = m
m.q = h
n.v = c
a.v = c
assert c.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: B = None
        self.txt = txt

c = A("c")
h = B("h")
m = B("m")
n = A("n")
a = A("a")

c.v = n
h.q = m
m.q = h
n.v = c
a.v = c
assert c.v.v.v.txt == "n"