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

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

e = A("e")
c = B("c")
l = A("l")
g = A("g")
j = B("j")
m = B("m")
f = A("f")
i = A("i")

e.p = l
c.r = i
c.u = g
l.p = i
g.p = l
j.r = f
j.u = l
m.r = i
m.u = e
f.p = g
i.p = g
assert e.p.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.p: A = None
        self.txt = txt

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

e = A("e")
c = B("c")
l = A("l")
g = A("g")
j = B("j")
m = B("m")
f = A("f")
i = A("i")

e.p = l
c.r = i
c.u = g
l.p = i
g.p = l
j.r = f
j.u = l
m.r = i
m.u = e
f.p = g
i.p = g
assert e.p.p.p.txt == "g"