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

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

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

l.y = j
j.w = n
j.p = n
n.y = d
d.w = l
d.p = k
k.y = d
assert n.y.p.y.w.txt == "
class A:
    def __init__(self, txt: str):
        self.y: B = None
        self.txt = txt

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

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

l.y = j
j.w = n
j.p = n
n.y = d
d.w = l
d.p = k
k.y = d
assert n.y.p.y.w.txt == "l"