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

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

k.o = n
k.r = m
n.s = d
m.o = d
m.r = k
e.o = n
e.r = k
f.o = n
f.r = m
j.o = n
j.r = k
d.s = n
assert e.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

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

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