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

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

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

class D:
    def __init__(self, txt: str):
        self.q: A = None
        self.z: A = None
        self.w: A = None
        self.v: A = None
        self.txt = txt

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

b.r = h
b.x = h
j.x = b
c.y = j
c.v = j
c.z = g
f.q = b
f.z = b
f.w = h
f.v = h
h.r = b
h.x = b
g.y = j
g.v = j
g.z = c
assert g.v.x.r.x.x.x.txt == "
class A:
    def __init__(self, txt: str):
        self.r: A = None
        self.x: A = None
        self.txt = txt

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

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

class D:
    def __init__(self, txt: str):
        self.q: A = None
        self.z: A = None
        self.w: A = None
        self.v: A = None
        self.txt = txt

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

b.r = h
b.x = h
j.x = b
c.y = j
c.v = j
c.z = g
f.q = b
f.z = b
f.w = h
f.v = h
h.r = b
h.x = b
g.y = j
g.v = j
g.z = c
assert g.v.x.r.x.x.x.txt == "b"