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

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

h = A("h")
k = B("k")
j = A("j")
d = B("d")
c = A("c")
n = B("n")
b = B("b")
e = A("e")

h.s = b
k.r = d
k.x = d
j.s = k
d.r = b
d.x = k
c.s = d
n.r = b
n.x = k
b.r = d
b.x = k
e.s = n
assert d.x.x.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.s: B = None
        self.txt = txt

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

h = A("h")
k = B("k")
j = A("j")
d = B("d")
c = A("c")
n = B("n")
b = B("b")
e = A("e")

h.s = b
k.r = d
k.x = d
j.s = k
d.r = b
d.x = k
c.s = d
n.r = b
n.x = k
b.r = d
b.x = k
e.s = n
assert d.x.x.r.x.txt == "k"