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

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

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

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

c = A("c")
b = B("b")
m = C("m")
e = D("e")
h = D("h")
k = B("k")
i = A("i")

c.u = i
b.u = i
b.q = c
b.r = c
m.s = b
m.p = b
m.z = c
e.z = m
h.z = m
k.u = c
k.q = c
k.r = i
i.u = c
assert c.u.u.u.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.txt = txt

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

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

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

c = A("c")
b = B("b")
m = C("m")
e = D("e")
h = D("h")
k = B("k")
i = A("i")

c.u = i
b.u = i
b.q = c
b.r = c
m.s = b
m.p = b
m.z = c
e.z = m
h.z = m
k.u = c
k.q = c
k.r = i
i.u = c
assert c.u.u.u.u.txt == "c"