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

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

k = A("k")
c = B("c")
h = A("h")
j = A("j")
a = A("a")
d = A("d")
m = A("m")

k.w = c
k.r = h
c.u = m
c.x = a
h.w = c
h.r = a
j.w = c
j.r = h
a.w = c
a.r = m
d.w = c
d.r = m
m.w = c
m.r = j
assert k.r.w.x.txt == "
class A:
    def __init__(self, txt: str):
        self.w: B = None
        self.r: A = None
        self.txt = txt

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

k = A("k")
c = B("c")
h = A("h")
j = A("j")
a = A("a")
d = A("d")
m = A("m")

k.w = c
k.r = h
c.u = m
c.x = a
h.w = c
h.r = a
j.w = c
j.r = h
a.w = c
a.r = m
d.w = c
d.r = m
m.w = c
m.r = j
assert k.r.w.x.txt == "a"