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

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

l = A("l")
k = B("k")
n = B("n")
d = A("d")
g = B("g")

l.o = d
k.s = l
n.s = d
d.o = l
g.s = d
assert l.o.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.o: A = None
        self.txt = txt

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

l = A("l")
k = B("k")
n = B("n")
d = A("d")
g = B("g")

l.o = d
k.s = l
n.s = d
d.o = l
g.s = d
assert l.o.o.o.o.txt == "l"