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

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

d = A("d")
j = B("j")
a = B("a")
n = B("n")
f = A("f")
m = A("m")
e = A("e")
g = B("g")

d.s = f
d.r = n
j.o = a
a.o = g
n.o = g
f.s = d
f.r = n
m.s = e
m.r = n
e.s = f
e.r = n
g.o = a
assert a.o.o.o.txt == "
class A:
    def __init__(self, txt: str):
        self.s: A = None
        self.r: B = None
        self.txt = txt

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

d = A("d")
j = B("j")
a = B("a")
n = B("n")
f = A("f")
m = A("m")
e = A("e")
g = B("g")

d.s = f
d.r = n
j.o = a
a.o = g
n.o = g
f.s = d
f.r = n
m.s = e
m.r = n
e.s = f
e.r = n
g.o = a
assert a.o.o.o.txt == "g"