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

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

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

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

d = A("d")
f = B("f")
b = C("b")
m = D("m")
n = B("n")
k = D("k")
c = B("c")
j = C("j")
a = B("a")

d.s = k
f.o = d
f.x = d
b.x = n
b.t = d
m.r = k
m.s = b
n.o = d
n.x = d
k.r = m
k.s = j
c.o = d
c.x = d
j.x = a
j.t = d
a.o = d
a.x = d
assert d.s.r.r.txt == "
class A:
    def __init__(self, txt: str):
        self.s: D = None
        self.txt = txt

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

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

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

d = A("d")
f = B("f")
b = C("b")
m = D("m")
n = B("n")
k = D("k")
c = B("c")
j = C("j")
a = B("a")

d.s = k
f.o = d
f.x = d
b.x = n
b.t = d
m.r = k
m.s = b
n.o = d
n.x = d
k.r = m
k.s = j
c.o = d
c.x = d
j.x = a
j.t = d
a.o = d
a.x = d
assert d.s.r.r.txt == "k"