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

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

j = A("j")
l = B("l")
e = B("e")
d = A("d")

j.o = e
j.s = e
l.u = j
l.x = j
e.u = j
e.x = d
d.o = e
d.s = e
assert l.x.s.x.txt == "
class A:
    def __init__(self, txt: str):
        self.o: B = None
        self.s: B = None
        self.txt = txt

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

j = A("j")
l = B("l")
e = B("e")
d = A("d")

j.o = e
j.s = e
l.u = j
l.x = j
e.u = j
e.x = d
d.o = e
d.s = e
assert l.x.s.x.txt == "d"