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

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

c = A("c")
g = B("g")
j = B("j")
i = A("i")
k = B("k")
e = B("e")
n = A("n")
d = A("d")

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

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

c = A("c")
g = B("g")
j = B("j")
i = A("i")
k = B("k")
e = B("e")
n = A("n")
d = A("d")

c.v = n
g.s = i
g.r = j
j.s = d
j.r = k
i.v = d
k.s = n
k.r = j
e.s = d
e.r = k
n.v = c
d.v = n
assert d.v.v.v.txt == "n"