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

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

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

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

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

h.z = i
h.r = b
h.t = m
h.y = d
i.z = m
i.o = b
i.x = d
f.p = d
d.q = m
d.z = b
b.z = i
b.r = h
b.t = m
b.y = m
m.q = d
m.z = h
assert m.q.q.q.txt == "
class A:
    def __init__(self, txt: str):
        self.z: B = None
        self.r: A = None
        self.t: D = None
        self.y: D = None
        self.txt = txt

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

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

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

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

h.z = i
h.r = b
h.t = m
h.y = d
i.z = m
i.o = b
i.x = d
f.p = d
d.q = m
d.z = b
b.z = i
b.r = h
b.t = m
b.y = m
m.q = d
m.z = h
assert m.q.q.q.txt == "d"