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

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

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

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

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

b.p = d
g.y = i
g.w = l
k.r = j
h.v = l
l.r = m
d.r = m
i.y = g
i.w = k
e.r = j
m.v = e
j.v = k
assert e.r.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.p: C = None
        self.txt = txt

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

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

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

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

b.p = d
g.y = i
g.w = l
k.r = j
h.v = l
l.r = m
d.r = m
i.y = g
i.w = k
e.r = j
m.v = e
j.v = k
assert e.r.v.r.txt == "j"