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

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

a = A("a")
j = B("j")
b = A("b")
e = B("e")

a.y = j
j.o = a
b.y = e
e.o = a
assert j.o.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.o: A = None
        self.txt = txt

a = A("a")
j = B("j")
b = A("b")
e = B("e")

a.y = j
j.o = a
b.y = e
e.o = a
assert j.o.y.o.y.txt == "j"