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

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

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

d = A("d")
n = B("n")
m = C("m")
k = A("k")
c = C("c")
j = C("j")

d.y = k
d.z = n
n.y = d
n.q = d
n.s = j
m.y = c
k.y = d
k.z = n
c.y = m
j.y = c
assert c.y.y.y.y.txt == "
class A:
    def __init__(self, txt: str):
        self.y: A = None
        self.z: B = None
        self.txt = txt

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

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

d = A("d")
n = B("n")
m = C("m")
k = A("k")
c = C("c")
j = C("j")

d.y = k
d.z = n
n.y = d
n.q = d
n.s = j
m.y = c
k.y = d
k.z = n
c.y = m
j.y = c
assert c.y.y.y.y.txt == "c"