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

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

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

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

b = A("b")
e = B("e")
h = C("h")
k = D("k")
l = C("l")
g = A("g")
j = D("j")
n = B("n")
d = B("d")

b.r = h
b.p = h
e.p = j
e.x = g
e.t = g
e.o = g
h.s = e
k.s = n
k.r = h
l.s = d
g.r = l
g.p = h
j.s = n
j.r = l
n.p = k
n.x = b
n.o = b
n.t = g
d.p = k
d.x = g
d.o = g
d.t = b
assert j.r.s.t.txt == "
class A:
    def __init__(self, txt: str):
        self.r: C = None
        self.p: C = None
        self.txt = txt

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

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

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

b = A("b")
e = B("e")
h = C("h")
k = D("k")
l = C("l")
g = A("g")
j = D("j")
n = B("n")
d = B("d")

b.r = h
b.p = h
e.p = j
e.x = g
e.t = g
e.o = g
h.s = e
k.s = n
k.r = h
l.s = d
g.r = l
g.p = h
j.s = n
j.r = l
n.p = k
n.x = b
n.o = b
n.t = g
d.p = k
d.x = g
d.o = g
d.t = b
assert j.r.s.t.txt == "b"