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

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

c = A("c")
m = B("m")
j = B("j")
a = A("a")
g = B("g")
h = B("h")

c.r = a
c.o = a
m.s = a
m.p = a
j.s = a
j.p = c
a.r = c
a.o = c
g.s = c
g.p = c
h.s = a
h.p = a
assert h.p.o.r.r.o.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.o: A = None
        self.txt = txt

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

c = A("c")
m = B("m")
j = B("j")
a = A("a")
g = B("g")
h = B("h")

c.r = a
c.o = a
m.s = a
m.p = a
j.s = a
j.p = c
a.r = c
a.o = c
g.s = c
g.p = c
h.s = a
h.p = a
assert h.p.o.r.r.o.r.txt == "c"