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

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

l = A("l")
g = B("g")
a = A("a")
k = B("k")
i = B("i")
n = A("n")

l.p = n
g.s = n
g.u = i
a.p = n
k.s = a
k.u = g
i.s = n
i.u = g
n.p = l
assert i.u.s.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

l = A("l")
g = B("g")
a = A("a")
k = B("k")
i = B("i")
n = A("n")

l.p = n
g.s = n
g.u = i
a.p = n
k.s = a
k.u = g
i.s = n
i.u = g
n.p = l
assert i.u.s.p.txt == "l"