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

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

e = A("e")
g = B("g")
i = B("i")
c = B("c")
l = A("l")
k = B("k")

e.r = g
e.p = g
g.w = k
i.w = g
c.w = g
l.r = k
l.p = c
k.w = i
assert e.r.w.w.w.w.w.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.p: B = None
        self.txt = txt

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

e = A("e")
g = B("g")
i = B("i")
c = B("c")
l = A("l")
k = B("k")

e.r = g
e.p = g
g.w = k
i.w = g
c.w = g
l.r = k
l.p = c
k.w = i
assert e.r.w.w.w.w.w.txt == "i"