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

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

n = A("n")
c = B("c")
g = A("g")
l = B("l")
h = A("h")

n.x = h
n.v = l
c.q = n
c.x = g
g.x = h
g.v = l
l.q = g
l.x = g
h.x = n
h.v = c
assert h.v.q.v.q.txt == "
class A:
    def __init__(self, txt: str):
        self.x: A = None
        self.v: B = None
        self.txt = txt

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

n = A("n")
c = B("c")
g = A("g")
l = B("l")
h = A("h")

n.x = h
n.v = l
c.q = n
c.x = g
g.x = h
g.v = l
l.q = g
l.x = g
h.x = n
h.v = c
assert h.v.q.v.q.txt == "g"