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

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

n = A("n")
g = B("g")
f = B("f")
k = A("k")
h = B("h")
b = A("b")
i = B("i")

n.q = g
n.z = k
g.v = h
f.v = i
k.q = f
k.z = n
h.v = i
b.q = g
b.z = n
i.v = f
assert k.q.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.q: B = None
        self.z: A = None
        self.txt = txt

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

n = A("n")
g = B("g")
f = B("f")
k = A("k")
h = B("h")
b = A("b")
i = B("i")

n.q = g
n.z = k
g.v = h
f.v = i
k.q = f
k.z = n
h.v = i
b.q = g
b.z = n
i.v = f
assert k.q.v.v.txt == "f"