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

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

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

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

b = A("b")
c = B("c")
h = C("h")
k = D("k")

b.r = c
c.z = b
c.r = h
c.v = k
h.t = c
k.y = c
k.q = h
assert k.y.r.t.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: B = None
        self.txt = txt

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

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

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

b = A("b")
c = B("c")
h = C("h")
k = D("k")

b.r = c
c.z = b
c.r = h
c.v = k
h.t = c
k.y = c
k.q = h
assert k.y.r.t.r.txt == "h"