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

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

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

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

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

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

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