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

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

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

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

g = A("g")
e = B("e")
m = C("m")
n = D("n")
j = C("j")
k = A("k")
b = A("b")
c = A("c")

g.u = m
g.y = c
e.y = g
m.w = e
m.p = j
n.x = m
n.q = j
n.o = j
n.r = b
j.w = e
j.p = m
k.u = m
k.y = g
b.u = j
b.y = k
c.u = j
c.y = k
assert j.w.y.u.p.p.txt == "
class A:
    def __init__(self, txt: str):
        self.u: C = None
        self.y: A = None
        self.txt = txt

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

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

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

g = A("g")
e = B("e")
m = C("m")
n = D("n")
j = C("j")
k = A("k")
b = A("b")
c = A("c")

g.u = m
g.y = c
e.y = g
m.w = e
m.p = j
n.x = m
n.q = j
n.o = j
n.r = b
j.w = e
j.p = m
k.u = m
k.y = g
b.u = j
b.y = k
c.u = j
c.y = k
assert j.w.y.u.p.p.txt == "m"