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

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

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

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

f = A("f")
m = B("m")
g = C("g")
e = D("e")
h = C("h")
j = C("j")
c = B("c")

f.p = g
m.t = e
m.o = e
m.p = e
g.u = c
g.q = c
g.p = f
e.r = m
h.u = c
h.q = m
h.p = f
j.u = c
j.q = c
j.p = f
c.t = e
c.o = e
c.p = e
assert m.o.r.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

f = A("f")
m = B("m")
g = C("g")
e = D("e")
h = C("h")
j = C("j")
c = B("c")

f.p = g
m.t = e
m.o = e
m.p = e
g.u = c
g.q = c
g.p = f
e.r = m
h.u = c
h.q = m
h.p = f
j.u = c
j.q = c
j.p = f
c.t = e
c.o = e
c.p = e
assert m.o.r.t.r.txt == "m"