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

class B:
    def __init__(self, txt: str):
        self.z: D = None
        self.v: C = None
        self.w: C = None
        self.q: B = 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.p: A = None
        self.x: A = None
        self.txt = txt

d = A("d")
g = B("g")
h = C("h")
b = D("b")
a = A("a")
i = A("i")
c = B("c")

d.r = b
g.z = b
g.v = h
g.w = h
g.q = c
h.r = b
b.p = i
b.x = i
a.r = b
i.r = b
c.z = b
c.v = h
c.w = h
c.q = g
assert b.p.r.p.r.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.txt = txt

class B:
    def __init__(self, txt: str):
        self.z: D = None
        self.v: C = None
        self.w: C = None
        self.q: B = 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.p: A = None
        self.x: A = None
        self.txt = txt

d = A("d")
g = B("g")
h = C("h")
b = D("b")
a = A("a")
i = A("i")
c = B("c")

d.r = b
g.z = b
g.v = h
g.w = h
g.q = c
h.r = b
b.p = i
b.x = i
a.r = b
i.r = b
c.z = b
c.v = h
c.w = h
c.q = g
assert b.p.r.p.r.txt == "b"