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

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

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

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

m = A("m")
k = B("k")
n = C("n")
f = D("f")
g = D("g")
e = D("e")
d = B("d")
l = A("l")

m.t = l
m.p = e
k.x = f
n.r = l
f.x = k
f.q = g
f.y = n
g.x = d
g.q = f
g.y = n
e.x = d
e.q = g
e.y = n
d.x = e
l.t = m
l.p = f
assert l.t.p.q.y.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.t: A = None
        self.p: D = None
        self.txt = txt

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

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

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

m = A("m")
k = B("k")
n = C("n")
f = D("f")
g = D("g")
e = D("e")
d = B("d")
l = A("l")

m.t = l
m.p = e
k.x = f
n.r = l
f.x = k
f.q = g
f.y = n
g.x = d
g.q = f
g.y = n
e.x = d
e.q = g
e.y = n
d.x = e
l.t = m
l.p = f
assert l.t.p.q.y.r.p.txt == "f"