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

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

i = A("i")
e = B("e")
j = B("j")
d = A("d")
n = B("n")
c = A("c")
a = A("a")
f = A("f")
m = A("m")
k = A("k")

i.r = j
i.p = m
e.r = n
j.r = n
d.r = n
d.p = c
n.r = e
c.r = e
c.p = a
a.r = e
a.p = d
f.r = n
f.p = a
m.r = j
m.p = d
k.r = n
k.p = i
assert c.r.r.r.r.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.p: A = None
        self.txt = txt

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

i = A("i")
e = B("e")
j = B("j")
d = A("d")
n = B("n")
c = A("c")
a = A("a")
f = A("f")
m = A("m")
k = A("k")

i.r = j
i.p = m
e.r = n
j.r = n
d.r = n
d.p = c
n.r = e
c.r = e
c.p = a
a.r = e
a.p = d
f.r = n
f.p = a
m.r = j
m.p = d
k.r = n
k.p = i
assert c.r.r.r.r.r.r.r.txt == "e"