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

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

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

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

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

g.r = l
g.p = l
j.v = b
b.s = m
f.y = h
h.r = m
h.p = l
l.y = h
m.y = h
assert f.y.r.y.txt == "
class A:
    def __init__(self, txt: str):
        self.r: D = None
        self.p: D = None
        self.txt = txt

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

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

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

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

g.r = l
g.p = l
j.v = b
b.s = m
f.y = h
h.r = m
h.p = l
l.y = h
m.y = h
assert f.y.r.y.txt == "h"