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

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

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

c = A("c")
d = B("d")
a = C("a")
j = B("j")
e = B("e")
i = B("i")
k = C("k")
n = B("n")
f = A("f")

c.y = f
d.x = i
a.s = e
a.v = c
a.q = k
j.x = e
e.x = j
i.x = n
k.s = j
k.v = f
k.q = a
n.x = d
f.y = c
assert d.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.txt = txt

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

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

c = A("c")
d = B("d")
a = C("a")
j = B("j")
e = B("e")
i = B("i")
k = C("k")
n = B("n")
f = A("f")

c.y = f
d.x = i
a.s = e
a.v = c
a.q = k
j.x = e
e.x = j
i.x = n
k.s = j
k.v = f
k.q = a
n.x = d
f.y = c
assert d.x.x.x.txt == "d"