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

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

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

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

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

b.r = m
b.x = l
g.t = n
g.x = m
g.p = a
d.s = a
f.v = l
n.s = b
m.t = n
m.x = g
m.p = b
a.r = m
a.x = l
l.v = f
assert m.t.s.r.t.s.x.v.v.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.x: D = None
        self.txt = txt

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

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

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

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

b.r = m
b.x = l
g.t = n
g.x = m
g.p = a
d.s = a
f.v = l
n.s = b
m.t = n
m.x = g
m.p = b
a.r = m
a.x = l
l.v = f
assert m.t.s.r.t.s.x.v.v.txt == "l"