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

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

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

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

l = A("l")
g = B("g")
c = C("c")
d = D("d")
h = D("h")
n = A("n")
k = C("k")
m = A("m")
i = B("i")

l.u = h
g.y = h
c.q = m
d.p = i
h.p = g
n.u = d
k.q = l
m.u = h
i.y = h
assert k.q.u.p.y.txt == "
class A:
    def __init__(self, txt: str):
        self.u: D = None
        self.txt = txt

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

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

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

l = A("l")
g = B("g")
c = C("c")
d = D("d")
h = D("h")
n = A("n")
k = C("k")
m = A("m")
i = B("i")

l.u = h
g.y = h
c.q = m
d.p = i
h.p = g
n.u = d
k.q = l
m.u = h
i.y = h
assert k.q.u.p.y.txt == "h"