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

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

a = A("a")
f = B("f")
l = B("l")
c = A("c")
i = B("i")
k = A("k")
g = A("g")

a.p = k
a.s = l
f.y = l
l.y = i
c.p = a
c.s = f
i.y = f
k.p = c
k.s = f
g.p = a
g.s = i
assert g.s.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.s: B = None
        self.txt = txt

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

a = A("a")
f = B("f")
l = B("l")
c = A("c")
i = B("i")
k = A("k")
g = A("g")

a.p = k
a.s = l
f.y = l
l.y = i
c.p = a
c.s = f
i.y = f
k.p = c
k.s = f
g.p = a
g.s = i
assert g.s.y.y.y.txt == "i"