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

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

g = A("g")
b = B("b")
d = B("d")
m = A("m")
i = B("i")
e = A("e")
a = A("a")
k = B("k")

g.s = k
g.v = m
b.r = d
d.r = b
m.s = i
m.v = e
i.r = b
e.s = k
e.v = m
a.s = b
a.v = e
k.r = i
assert b.r.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.v: A = None
        self.txt = txt

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

g = A("g")
b = B("b")
d = B("d")
m = A("m")
i = B("i")
e = A("e")
a = A("a")
k = B("k")

g.s = k
g.v = m
b.r = d
d.r = b
m.s = i
m.v = e
i.r = b
e.s = k
e.v = m
a.s = b
a.v = e
k.r = i
assert b.r.r.r.txt == "d"