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

m = A("m")
n = B("n")
d = B("d")
j = A("j")
h = A("h")
k = B("k")
l = B("l")

m.y = n
n.o = j
d.o = m
j.y = l
h.y = d
k.o = h
l.o = m
assert d.o.y.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

m = A("m")
n = B("n")
d = B("d")
j = A("j")
h = A("h")
k = B("k")
l = B("l")

m.y = n
n.o = j
d.o = m
j.y = l
h.y = d
k.o = h
l.o = m
assert d.o.y.o.y.o.y.txt == "n"