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

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

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

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

f = A("f")
c = B("c")
e = C("e")
m = D("m")
n = A("n")
b = B("b")
j = A("j")

f.w = e
f.r = e
f.p = c
c.y = b
c.q = b
c.s = j
c.r = f
e.t = m
m.p = e
m.t = f
n.w = e
n.r = e
n.p = c
b.y = c
b.q = c
b.s = n
b.r = f
j.w = e
j.r = e
j.p = c
assert m.t.r.t.p.t.t.txt == "
class A:
    def __init__(self, txt: str):
        self.w: C = None
        self.r: C = None
        self.p: B = None
        self.txt = txt

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

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

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

f = A("f")
c = B("c")
e = C("e")
m = D("m")
n = A("n")
b = B("b")
j = A("j")

f.w = e
f.r = e
f.p = c
c.y = b
c.q = b
c.s = j
c.r = f
e.t = m
m.p = e
m.t = f
n.w = e
n.r = e
n.p = c
b.y = c
b.q = c
b.s = n
b.r = f
j.w = e
j.r = e
j.p = c
assert m.t.r.t.p.t.t.txt == "f"