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

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

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

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

m = A("m")
b = B("b")
n = C("n")
l = D("l")
a = C("a")
i = D("i")
g = A("g")
j = B("j")
d = A("d")
f = C("f")

m.u = d
m.p = n
b.r = i
b.x = l
b.o = j
b.q = d
n.s = f
n.q = g
l.y = f
l.z = g
a.s = f
a.q = d
i.y = n
i.z = g
g.u = m
g.p = f
j.r = l
j.x = i
j.o = b
j.q = d
d.u = g
d.p = f
f.s = a
f.q = d
assert f.q.p.q.txt == "
class A:
    def __init__(self, txt: str):
        self.u: A = None
        self.p: C = None
        self.txt = txt

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

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

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

m = A("m")
b = B("b")
n = C("n")
l = D("l")
a = C("a")
i = D("i")
g = A("g")
j = B("j")
d = A("d")
f = C("f")

m.u = d
m.p = n
b.r = i
b.x = l
b.o = j
b.q = d
n.s = f
n.q = g
l.y = f
l.z = g
a.s = f
a.q = d
i.y = n
i.z = g
g.u = m
g.p = f
j.r = l
j.x = i
j.o = b
j.q = d
d.u = g
d.p = f
f.s = a
f.q = d
assert f.q.p.q.txt == "d"