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

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

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

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

m = A("m")
f = B("f")
b = C("b")
d = D("d")
l = A("l")
j = A("j")

m.u = l
m.p = j
m.q = j
f.z = m
b.q = f
b.r = d
d.w = b
d.y = b
d.z = j
l.u = j
l.p = j
l.q = j
j.u = m
j.p = m
j.q = l
assert m.u.u.p.u.p.u.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.p: A = None
        self.q: A = None
        self.txt = txt

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

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

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

m = A("m")
f = B("f")
b = C("b")
d = D("d")
l = A("l")
j = A("j")

m.u = l
m.p = j
m.q = j
f.z = m
b.q = f
b.r = d
d.w = b
d.y = b
d.z = j
l.u = j
l.p = j
l.q = j
j.u = m
j.p = m
j.q = l
assert m.u.u.p.u.p.u.txt == "m"