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

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

i = A("i")
n = B("n")
d = B("d")
m = A("m")
j = A("j")
c = A("c")

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

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

i = A("i")
n = B("n")
d = B("d")
m = A("m")
j = A("j")
c = A("c")

i.o = c
i.r = c
n.p = m
n.o = c
d.p = j
d.o = c
m.o = i
m.r = j
j.o = c
j.r = c
c.o = i
c.r = m
assert m.r.r.r.r.txt == "j"