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

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

i = A("i")
d = B("d")
n = A("n")
g = B("g")
f = B("f")
h = A("h")
k = A("k")
e = A("e")
a = A("a")

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

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

i = A("i")
d = B("d")
n = A("n")
g = B("g")
f = B("f")
h = A("h")
k = A("k")
e = A("e")
a = A("a")

i.r = a
d.s = g
d.v = f
n.r = h
g.s = d
g.v = f
f.s = d
f.v = g
h.r = a
k.r = i
e.r = h
a.r = k
assert d.s.s.v.s.txt == "d"