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

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

i = A("i")
l = B("l")
m = B("m")
a = B("a")
c = A("c")
d = B("d")

i.u = c
i.p = l
l.s = i
m.s = i
a.s = c
c.u = i
c.p = a
d.s = i
assert c.p.s.u.p.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.p: B = None
        self.txt = txt

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

i = A("i")
l = B("l")
m = B("m")
a = B("a")
c = A("c")
d = B("d")

i.u = c
i.p = l
l.s = i
m.s = i
a.s = c
c.u = i
c.p = a
d.s = i
assert c.p.s.u.p.s.txt == "i"