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

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

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

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

f = A("f")
h = B("h")
e = C("e")
i = D("i")
d = C("d")
b = A("b")
j = D("j")

f.w = b
h.v = e
h.w = d
e.p = i
e.q = i
e.r = h
e.v = d
i.r = j
d.p = i
d.q = i
d.r = h
d.v = e
b.w = f
j.r = i
assert e.v.v.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.w: A = None
        self.txt = txt

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

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

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

f = A("f")
h = B("h")
e = C("e")
i = D("i")
d = C("d")
b = A("b")
j = D("j")

f.w = b
h.v = e
h.w = d
e.p = i
e.q = i
e.r = h
e.v = d
i.r = j
d.p = i
d.q = i
d.r = h
d.v = e
b.w = f
j.r = i
assert e.v.v.v.r.txt == "h"