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

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

b = A("b")
g = B("g")
c = A("c")
a = B("a")
i = A("i")

b.z = c
b.o = a
g.v = c
c.z = b
c.o = a
a.v = b
i.z = b
i.o = g
assert b.o.v.o.v.txt == "
class A:
    def __init__(self, txt: str):
        self.z: A = None
        self.o: B = None
        self.txt = txt

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

b = A("b")
g = B("g")
c = A("c")
a = B("a")
i = A("i")

b.z = c
b.o = a
g.v = c
c.z = b
c.o = a
a.v = b
i.z = b
i.o = g
assert b.o.v.o.v.txt == "b"