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

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

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

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

h = A("h")
j = B("j")
i = C("i")
c = D("c")
f = A("f")
d = B("d")
m = A("m")

h.r = c
j.y = d
j.z = c
j.q = f
j.w = h
i.t = m
i.y = f
c.y = m
c.q = d
c.t = d
f.r = c
d.y = j
d.z = c
d.q = m
d.w = f
m.r = c
assert m.r.y.r.y.r.y.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

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

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

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

h = A("h")
j = B("j")
i = C("i")
c = D("c")
f = A("f")
d = B("d")
m = A("m")

h.r = c
j.y = d
j.z = c
j.q = f
j.w = h
i.t = m
i.y = f
c.y = m
c.q = d
c.t = d
f.r = c
d.y = j
d.z = c
d.q = m
d.w = f
m.r = c
assert m.r.y.r.y.r.y.r.txt == "c"