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.x: A = None
        self.txt = txt

c = A("c")
k = B("k")
d = B("d")
e = A("e")
f = B("f")
g = A("g")
h = B("h")
l = A("l")
a = A("a")

c.r = k
k.s = d
k.x = g
d.s = f
d.x = c
e.r = f
f.s = k
f.x = a
g.r = h
h.s = d
h.x = c
l.r = h
a.r = d
assert d.s.s.x.r.x.r.x.r.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.x: A = None
        self.txt = txt

c = A("c")
k = B("k")
d = B("d")
e = A("e")
f = B("f")
g = A("g")
h = B("h")
l = A("l")
a = A("a")

c.r = k
k.s = d
k.x = g
d.s = f
d.x = c
e.r = f
f.s = k
f.x = a
g.r = h
h.s = d
h.x = c
l.r = h
a.r = d
assert d.s.s.x.r.x.r.x.r.txt == "h"