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

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

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

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

c = A("c")
k = B("k")
l = C("l")
h = D("h")
i = A("i")
m = B("m")
e = C("e")
f = D("f")
j = C("j")

c.r = m
c.v = m
k.y = m
k.q = m
k.p = f
k.x = c
l.y = i
l.v = f
l.p = e
h.p = m
i.r = m
i.v = k
m.y = k
m.q = k
m.p = f
m.x = i
e.y = i
e.v = h
e.p = j
f.p = m
j.y = i
j.v = h
j.p = e
assert m.q.x.r.p.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.v: B = None
        self.txt = txt

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

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

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

c = A("c")
k = B("k")
l = C("l")
h = D("h")
i = A("i")
m = B("m")
e = C("e")
f = D("f")
j = C("j")

c.r = m
c.v = m
k.y = m
k.q = m
k.p = f
k.x = c
l.y = i
l.v = f
l.p = e
h.p = m
i.r = m
i.v = k
m.y = k
m.q = k
m.p = f
m.x = i
e.y = i
e.v = h
e.p = j
f.p = m
j.y = i
j.v = h
j.p = e
assert m.q.x.r.p.txt == "f"