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

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

b = A("b")
j = B("j")
c = A("c")
f = B("f")
h = B("h")

b.v = c
j.z = f
j.q = b
c.v = b
f.z = j
f.q = c
h.z = f
h.q = c
assert j.q.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.z: B = None
        self.q: A = None
        self.txt = txt

b = A("b")
j = B("j")
c = A("c")
f = B("f")
h = B("h")

b.v = c
j.z = f
j.q = b
c.v = b
f.z = j
f.q = c
h.z = f
h.q = c
assert j.q.v.v.v.txt == "c"