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

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

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

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

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

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

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