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

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

g = A("g")
h = B("h")
m = A("m")
k = A("k")
d = B("d")
c = A("c")
j = A("j")
l = B("l")

g.r = l
h.s = d
m.r = l
k.r = l
d.s = h
c.r = l
j.r = l
l.s = d
assert d.s.s.s.s.s.s.s.s.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

g = A("g")
h = B("h")
m = A("m")
k = A("k")
d = B("d")
c = A("c")
j = A("j")
l = B("l")

g.r = l
h.s = d
m.r = l
k.r = l
d.s = h
c.r = l
j.r = l
l.s = d
assert d.s.s.s.s.s.s.s.s.txt == "d"