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

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

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

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

a = A("a")
k = B("k")
l = C("l")
d = D("d")
g = C("g")
b = A("b")
h = B("h")

a.y = l
a.p = g
k.q = l
k.x = g
k.s = a
l.y = d
d.r = k
g.y = d
b.y = g
b.p = g
h.q = g
h.x = l
h.s = a
assert b.y.y.r.x.txt == "
class A:
    def __init__(self, txt: str):
        self.y: C = None
        self.p: C = None
        self.txt = txt

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

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

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

a = A("a")
k = B("k")
l = C("l")
d = D("d")
g = C("g")
b = A("b")
h = B("h")

a.y = l
a.p = g
k.q = l
k.x = g
k.s = a
l.y = d
d.r = k
g.y = d
b.y = g
b.p = g
h.q = g
h.x = l
h.s = a
assert b.y.y.r.x.txt == "g"