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

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

l = A("l")
b = B("b")
g = B("g")

l.z = b
b.y = l
b.o = g
g.y = l
g.o = b
assert b.y.z.o.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.txt = txt

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

l = A("l")
b = B("b")
g = B("g")

l.z = b
b.y = l
b.o = g
g.y = l
g.o = b
assert b.y.z.o.txt == "g"