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

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

d = A("d")
h = B("h")
e = A("e")
n = B("n")
i = B("i")
c = B("c")

d.v = i
d.w = c
h.r = d
h.q = i
e.v = i
e.w = h
n.r = e
n.q = i
i.r = e
i.q = n
c.r = d
c.q = i
assert h.r.v.r.txt == "
class A:
    def __init__(self, txt: str):
        self.v: B = None
        self.w: B = None
        self.txt = txt

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

d = A("d")
h = B("h")
e = A("e")
n = B("n")
i = B("i")
c = B("c")

d.v = i
d.w = c
h.r = d
h.q = i
e.v = i
e.w = h
n.r = e
n.q = i
i.r = e
i.q = n
c.r = d
c.q = i
assert h.r.v.r.txt == "e"