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

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

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

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

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

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

d.o = k
c.s = g
a.o = b
j.o = k
g.o = c
i.s = g
k.s = n
n.o = b
b.s = a
assert g.o.s.o.s.txt == "g"