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

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

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

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

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

m.x = f
m.u = g
g.r = e
g.x = m
f.x = e
f.s = g
l.r = f
l.s = e
l.q = g
n.x = f
n.u = g
e.r = g
e.x = n
assert f.s.r.r.x.u.txt == "
class A:
    def __init__(self, txt: str):
        self.x: C = None
        self.u: B = None
        self.txt = txt

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

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

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

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

m.x = f
m.u = g
g.r = e
g.x = m
f.x = e
f.s = g
l.r = f
l.s = e
l.q = g
n.x = f
n.u = g
e.r = g
e.x = n
assert f.s.r.r.x.u.txt == "g"