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

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

f = A("f")
a = B("a")
k = B("k")
c = A("c")
g = A("g")
b = B("b")
n = A("n")
i = B("i")
j = A("j")
m = B("m")

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

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

f = A("f")
a = B("a")
k = B("k")
c = A("c")
g = A("g")
b = B("b")
n = A("n")
i = B("i")
j = A("j")
m = B("m")

f.o = m
f.r = c
a.s = m
k.s = i
c.o = m
c.r = g
g.o = i
g.r = j
b.s = k
n.o = a
n.r = g
i.s = m
j.o = m
j.r = n
m.s = a
assert g.o.s.s.s.s.txt == "a"