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

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

g = A("g")
d = B("d")
k = B("k")
e = B("e")
m = A("m")

g.u = d
g.v = m
d.r = k
d.s = k
k.r = d
k.s = e
e.r = k
e.s = d
m.u = k
m.v = g
assert d.s.r.r.r.s.txt == "
class A:
    def __init__(self, txt: str):
        self.u: B = None
        self.v: A = None
        self.txt = txt

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

g = A("g")
d = B("d")
k = B("k")
e = B("e")
m = A("m")

g.u = d
g.v = m
d.r = k
d.s = k
k.r = d
k.s = e
e.r = k
e.s = d
m.u = k
m.v = g
assert d.s.r.r.r.s.txt == "k"